/** * Hook method dispatched by the IntentService framework to download the image requested via data * in an intent, store the image in a local file on the local device, and return the image file's * URI back to the ImageModelImpl's Handler via the Messenger passed with the intent. */ @Override public void onHandleIntent(Intent intent) { // Extract the RequestMessage from the intent. final RequestMessage requestMessage = RequestMessage.makeRequestMessage((Message) intent.getParcelableExtra(REQUEST_MESSAGE)); // Extract the URL for the image to download. // TODO -x- you fill in here. Uri uri = requestMessage.getImageURL(); // Download the requested image. // TODO -x??- you fill in here. Uri path = requestMessage.getDirectoryPathname(); // Extract the request code. // TODO -x- you fill in here. int requestCode = requestMessage.getRequestCode(); // Extract the Messenger stored as an extra in the // intent under the key MESSENGER. // TODO -x- you fill in here. Messenger messenger = requestMessage.getMessenger(); // Send the path to the image file back to the // MainActivity via the messenger. // TODO -x- you fill in here. sendPath(messenger, path, uri, requestCode); }
/** Send the @a pathToImageFile back to the ImageModelImp's Handler via the @a Messenger. */ private void sendPath(Messenger messenger, Uri pathToImageFile, Uri url, int requestCode) { // Call the makeReplyMessage() factory method to create // Message. // TODO -x- you fill in here. RequestMessage requestMessage = RequestMessage.makeRequestMessage(requestCode, url, pathToImageFile, messenger); try { // Send the path to the image file back to the // ImageModelImpl's Handler via the Messenger. // TODO -x- you fill in here. requestMessage.getMessenger().send(requestMessage.getMessage()); } catch (RemoteException e) { Log.e(getClass().getName(), "Exception while sending reply message back to Activity.", e); } }