List of usage examples for android.content Intent getParcelableExtra
public <T extends Parcelable> T getParcelableExtra(String name)
From source file:edu.mit.media.funf.probe.Probe.java
protected void onHandleIntent(Intent intent) { String action = intent.getAction(); Log.d(TAG, getDisplayName() + ": " + action); Log.d(TAG, "Component: " + intent.getComponent() == null ? "<none>" : intent.getComponent().getClassName()); getHistoryPrefs();/* w w w.j a v a 2 s . c o m*/ if (requestsIntent == null) { loadRequestsIntent(intent); if (requestsIntent == null) { Log.d(TAG, "Did not successfully load requests Intent"); return; } } updateRequests(); Log.d(TAG, "RunIntent " + (requestsIntent == null ? "<null>" : "exists")); if (intent.getComponent().getClassName().equals(Probe.class.getName())) { // Internally queued, not available outside of probe class if (ACTION_RUN.equals(action) || ACTION_STOP.equals(action) || ACTION_DISABLE.equals(action)) { ProbeScheduler scheduler = getScheduler(); ArrayList<Intent> requests = requestsIntent.getParcelableArrayListExtra(INTERNAL_REQUESTS_KEY); Log.d(TAG, "Requests:" + requests); if (isAvailableOnDevice() && !ACTION_DISABLE.equals(action) && scheduler.shouldBeEnabled(this, requests)) { if (ACTION_RUN.equals(action)) { _run(); } else { _stop(); } } else { _disable(); updateInternalRequestsPendingIntent(); } Long nextScheduledTime = scheduler.scheduleNextRun(this, requests); Log.d(TAG, "Next scheduled time: " + nextScheduledTime); if (nextScheduledTime == null) { getHistoryPrefs().edit().remove(NEXT_RUN_TIME_KEY).commit(); } else { getHistoryPrefs().edit().putLong(NEXT_RUN_TIME_KEY, nextScheduledTime).commit(); } } else if (ACTION_INTERNAL_CALLBACK_REGISTERED.equals(action)) { Intent callbackRegisteredIntent = intent.getParcelableExtra(INTERNAL_CALLBACK_INTENT); PendingIntent callback = intent.getParcelableExtra(CALLBACK_KEY); _callback_registered(callbackRegisteredIntent, callback); } } else if (ACTION_REQUEST.equals(action) || action == null) { ArrayList<Bundle> test = Utils.getArrayList(intent.getExtras(), REQUESTS_KEY); Log.d(TAG, "REQUEST: " + test); boolean succesfullyQueued = queueRequest(intent); if (succesfullyQueued) { run(); } } else if (ACTION_INTERNAL_REQUESTS.equals(action)) { } else if (ACTION_RUN.equals(action)) { // External stop, queue up stop run(); } else if (ACTION_STOP.equals(action)) { // External stop, queue up stop stop(); } else if (ACTION_DISABLE.equals(action)) { // External disable, queue up disable disable(); } else if (ACTION_SEND_DETAILS.equals(action)) { // DOESN'T NEED requests PendingIntent callback = intent.getParcelableExtra(CALLBACK_KEY); sendProbeDetails(callback); } else if (ACTION_SEND_CONFIGURATION.equals(action)) { //PendingIntent callback = intent.getParcelableExtra(CALLBACK_KEY); //sendProbeConfiguration(callback); } else if (ACTION_SEND_STATUS.equals(action)) { // DOESN'T NEED requests PendingIntent callback = intent.getParcelableExtra(CALLBACK_KEY); sendProbeStatus(callback); } else { onHandleCustomIntent(intent); } }
From source file:com.android.contacts.ContactSaveService.java
private void createGroup(Intent intent) { String accountType = intent.getStringExtra(EXTRA_ACCOUNT_TYPE); String accountName = intent.getStringExtra(EXTRA_ACCOUNT_NAME); String dataSet = intent.getStringExtra(EXTRA_DATA_SET); String label = intent.getStringExtra(EXTRA_GROUP_LABEL); final long[] rawContactsToAdd = intent.getLongArrayExtra(EXTRA_RAW_CONTACTS_TO_ADD); // Create the new group final Uri groupUri = mGroupsDao.create(label, new AccountWithDataSet(accountName, accountType, dataSet)); final ContentResolver resolver = getContentResolver(); // If there's no URI, then the insertion failed. Abort early because group members can't be // added if the group doesn't exist if (groupUri == null) { Log.e(TAG, "Couldn't create group with label " + label); return;/*from w ww . ja va 2s . c o m*/ } // Add new group members addMembersToGroup(resolver, rawContactsToAdd, ContentUris.parseId(groupUri)); ContentValues values = new ContentValues(); // TODO: Move this into the contact editor where it belongs. This needs to be integrated // with the way other intent extras that are passed to the // {@link ContactEditorActivity}. values.clear(); values.put(Data.MIMETYPE, GroupMembership.CONTENT_ITEM_TYPE); values.put(GroupMembership.GROUP_ROW_ID, ContentUris.parseId(groupUri)); Intent callbackIntent = intent.getParcelableExtra(EXTRA_CALLBACK_INTENT); callbackIntent.setData(groupUri); // TODO: This can be taken out when the above TODO is addressed callbackIntent.putExtra(ContactsContract.Intents.Insert.DATA, Lists.newArrayList(values)); deliverCallback(callbackIntent); }
From source file:com.money.manager.ex.transactions.EditTransactionCommonFunctions.java
public void onActivityResult(int requestCode, int resultCode, Intent data) { if ((resultCode != Activity.RESULT_OK) || (data == null)) return;/*from w ww .j ava 2 s . c o m*/ setDirty(true); String stringExtra; switch (requestCode) { case RequestCodes.PAYEE: this.transactionEntity .setPayeeId(data.getIntExtra(PayeeActivity.INTENT_RESULT_PAYEEID, Constants.NOT_SET)); payeeName = data.getStringExtra(PayeeActivity.INTENT_RESULT_PAYEENAME); // select last category used from payee. Only if category has not been entered earlier. if (!isSplitSelected() && !this.transactionEntity.hasCategory()) { if (setCategoryFromPayee(this.transactionEntity.getPayeeId())) { displayCategoryName(); // refresh UI } } // refresh UI showPayeeName(); break; case RequestCodes.ACCOUNT: transactionEntity.setAccountToId( data.getIntExtra(AccountListActivity.INTENT_RESULT_ACCOUNTID, Constants.NOT_SET)); mToAccountName = data.getStringExtra(AccountListActivity.INTENT_RESULT_ACCOUNTNAME); break; case RequestCodes.AMOUNT: onFinishedInputAmountDialog(R.id.textViewAmount, Calculator.getAmountFromResult(data)); break; case RequestCodes.AMOUNT_TO: onFinishedInputAmountDialog(R.id.textViewToAmount, Calculator.getAmountFromResult(data)); break; case RequestCodes.CATEGORY: this.transactionEntity .setCategoryId(data.getIntExtra(CategoryListActivity.INTENT_RESULT_CATEGID, Constants.NOT_SET)); categoryName = data.getStringExtra(CategoryListActivity.INTENT_RESULT_CATEGNAME); this.transactionEntity.setSubcategoryId( data.getIntExtra(CategoryListActivity.INTENT_RESULT_SUBCATEGID, Constants.NOT_SET)); subCategoryName = data.getStringExtra(CategoryListActivity.INTENT_RESULT_SUBCATEGNAME); // refresh UI category displayCategoryName(); break; case RequestCodes.SPLIT_TX: mSplitTransactions = Parcels .unwrap(data.getParcelableExtra(SplitCategoriesActivity.INTENT_RESULT_SPLIT_TRANSACTION)); // deleted items Parcelable parcelDeletedSplits = data .getParcelableExtra(SplitCategoriesActivity.INTENT_RESULT_SPLIT_TRANSACTION_DELETED); if (parcelDeletedSplits != null) { mSplitTransactionsDeleted = Parcels.unwrap(parcelDeletedSplits); } // Splits and deleted splits must be restored before any action takes place. onSplitConfirmed(getSplitTransactions()); break; } }
From source file:com.support.android.designlibdemo.activities.CampaignDetailActivity.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == Activity.RESULT_OK) { if (requestCode == TAKE_PHOTO_CODE) { photoBitmap = BitmapFactory.decodeFile(photoUri.getPath()); Bitmap resizedImage = BitmapScaler.scaleToFitWidth(photoBitmap, 300); ivCampaignImage.getAdjustViewBounds(); ivCampaignImage.setScaleType(ImageView.ScaleType.FIT_XY); //********** Update parse with image // Convert bitmap to a byte array ByteArrayOutputStream stream = new ByteArrayOutputStream(); resizedImage.compress(Bitmap.CompressFormat.PNG, 100, stream); byte[] image = stream.toByteArray(); // Create the ParseFile with an image final ParseFile file = new ParseFile( "posted_by_user_" + ParseUser.getCurrentUser().getUsername() + ".jpg", image); //posting an image file with campaign id to Parse to Images object ParseObject photoPost = new ParseObject("Images"); photoPost.put("imagePost", file); photoPost.put("campaignId", campaign.getObjectId()); photoPost.saveInBackground(new SaveCallback() { @Override//w ww. j av a 2s . c o m public void done(ParseException e) { getImagesUploadedByUserForCampaign(campaign.getObjectId()); } }); } else if (requestCode == PICK_PHOTO_CODE) { photoUri = data.getData(); try { photoBitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), photoUri); } catch (IOException e) { e.printStackTrace(); } Bitmap resizedImage = BitmapScaler.scaleToFitWidth(photoBitmap, 300); ivCampaignImage.getAdjustViewBounds(); ivCampaignImage.setScaleType(ImageView.ScaleType.FIT_XY); //********** Update parse with image //ivCampaignImage.setImageBitmap(resizedImage); // Convert bitmap to a byte array ByteArrayOutputStream stream = new ByteArrayOutputStream(); resizedImage.compress(Bitmap.CompressFormat.PNG, 100, stream); byte[] image = stream.toByteArray(); // Create the ParseFile with an image final ParseFile file = new ParseFile( "posted_by_user_" + ParseUser.getCurrentUser().getUsername() + ".jpg", image); //posting an image file with campaign id to Parse to Images object ParseObject photoPost = new ParseObject("Images"); photoPost.put("imagePost", file); photoPost.put("campaignId", campaign.getObjectId()); photoPost.saveInBackground(); photoPost.saveInBackground(new SaveCallback() { @Override public void done(ParseException e) { getImagesUploadedByUserForCampaign(campaign.getObjectId()); } }); } else if (requestCode == CROP_PHOTO_CODE) { photoBitmap = data.getParcelableExtra("data"); ivCampaignImage.getAdjustViewBounds(); ivCampaignImage.setScaleType(ImageView.ScaleType.FIT_XY); ivCampaignImage.setImageBitmap(photoBitmap); Toast.makeText(this, "I just took a picture", Toast.LENGTH_LONG).show(); } } }
From source file:com.github.michalbednarski.intentslab.editor.IntentEditorActivity.java
@Override protected void onActivityResult(int requestCode, final int resultCode, final Intent resultIntent) { if (requestCode == REQUEST_CODE_TEST_STARTACTIVITYFORRESULT) { // Result of tested startActivityForResult if (resultIntent == null) { Toast.makeText(this, getString(R.string.startactivityforresult_no_result, resultCode), Toast.LENGTH_SHORT).show(); } else {//from w w w . ja v a2 s . com AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this) .setMessage(getString(R.string.startactivityforresult_got_result)); if (isInterceptedIntent() && (getCallingPackage() != null)) { alertBuilder.setPositiveButton(getString(R.string.edit_intercepted_result), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { startActivityForResult( new Intent(IntentEditorActivity.this, IntentEditorActivity.class) .putExtra(EXTRA_INTENT, resultIntent) .putExtra(EXTRA_COMPONENT_TYPE, IntentEditorConstants.RESULT) .putExtra(EXTRA_METHOD_ID, resultCode) .putExtra(EXTRA_FORWARD_ABLE_RESULT, true), REQUEST_CODE_RESULT_INTENT_EDITOR); } }).setNeutralButton(getString(R.string.forward_intercepted_result), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { setResult(resultCode, resultIntent); finish(); } }); } else { alertBuilder.setPositiveButton(getString(R.string.startactivityforresult_view_result), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { startActivity(new Intent(IntentEditorActivity.this, IntentEditorActivity.class) .putExtra(EXTRA_INTENT, resultIntent) .putExtra(EXTRA_COMPONENT_TYPE, IntentEditorConstants.RESULT)); } }); } alertBuilder.setNegativeButton(getString(R.string.cancel), null).show(); } } else if (requestCode == REQUEST_CODE_RESULT_INTENT_EDITOR) { // Result intent editor requesting forward result if (resultIntent != null && resultIntent.hasExtra(EXTRA_FORWARD_RESULT_INTENT)) { setResult(resultIntent.getIntExtra(EXTRA_FORWARD_RESULT_CODE, 0), (Intent) resultIntent.getParcelableExtra(EXTRA_FORWARD_RESULT_INTENT)); finish(); } } else if (requestCode == REQUEST_CODE_REQUEST_INTENT_TRACKER_PERMISSION) { if (resultCode == RESULT_OK) { createIntentTracker(); } } else { super.onActivityResult(requestCode, resultCode, resultIntent); } }
From source file:it.feio.android.omninotes.DetailFragment.java
@SuppressLint("NewApi") @Override/*from ww w. j a va2 s. c om*/ public void onActivityResult(int requestCode, int resultCode, Intent intent) { // Fetch uri from activities, store into adapter and refresh adapter Attachment attachment; if (resultCode == Activity.RESULT_OK) { switch (requestCode) { case TAKE_PHOTO: attachment = new Attachment(attachmentUri, Constants.MIME_TYPE_IMAGE); addAttachment(attachment); mAttachmentAdapter.notifyDataSetChanged(); mGridView.autoresize(); break; case TAKE_VIDEO: // Gingerbread doesn't allow custom folder so data are retrieved from intent if (Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD_MR1) { attachment = new Attachment(attachmentUri, Constants.MIME_TYPE_VIDEO); } else { attachment = new Attachment(intent.getData(), Constants.MIME_TYPE_VIDEO); } addAttachment(attachment); mAttachmentAdapter.notifyDataSetChanged(); mGridView.autoresize(); break; case FILES: onActivityResultManageReceivedFiles(intent); break; case SET_PASSWORD: noteTmp.setPasswordChecked(true); lockUnlock(); break; case SKETCH: attachment = new Attachment(attachmentUri, Constants.MIME_TYPE_SKETCH); addAttachment(attachment); mAttachmentAdapter.notifyDataSetChanged(); mGridView.autoresize(); break; case CATEGORY: mainActivity.showMessage(R.string.category_saved, ONStyle.CONFIRM); Category category = intent.getParcelableExtra("category"); noteTmp.setCategory(category); setTagMarkerColor(category); break; case DETAIL: mainActivity.showMessage(R.string.note_updated, ONStyle.CONFIRM); break; } } }
From source file:com.sip.pwc.sipphone.service.Downloader.java
@Override protected void onHandleIntent(Intent intent) { HttpGet getMethod = new HttpGet(intent.getData().toString()); int result = Activity.RESULT_CANCELED; String outPath = intent.getStringExtra(EXTRA_OUTPATH); boolean checkMd5 = intent.getBooleanExtra(EXTRA_CHECK_MD5, false); int icon = intent.getIntExtra(EXTRA_ICON, 0); String title = intent.getStringExtra(EXTRA_TITLE); boolean showNotif = (icon > 0 && !TextUtils.isEmpty(title)); // Build notification Builder nb = new Builder(this); nb.setWhen(System.currentTimeMillis()); nb.setContentTitle(title);/* w ww . jav a 2 s . co m*/ nb.setSmallIcon(android.R.drawable.stat_sys_download); nb.setOngoing(true); Intent i = new Intent(this, SipHome.class); nb.setContentIntent(PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT)); RemoteViews contentView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.download_notif); contentView.setImageViewResource(R.id.status_icon, icon); contentView.setTextViewText(R.id.status_text, getResources().getString(R.string.downloading_text)); contentView.setProgressBar(R.id.status_progress, 50, 0, false); contentView.setViewVisibility(R.id.status_progress_wrapper, View.VISIBLE); nb.setContent(contentView); final Notification notification = showNotif ? nb.build() : null; notification.contentView = contentView; if (!TextUtils.isEmpty(outPath)) { try { File output = new File(outPath); if (output.exists()) { output.delete(); } if (notification != null) { notificationManager.notify(NOTIF_DOWNLOAD, notification); } ResponseHandler<Boolean> responseHandler = new FileStreamResponseHandler(output, new Progress() { private int oldState = 0; @Override public void run(long progress, long total) { //Log.d(THIS_FILE, "Progress is "+progress+" on "+total); int newState = (int) Math.round(progress * 50.0f / total); if (oldState != newState) { notification.contentView.setProgressBar(R.id.status_progress, 50, newState, false); notificationManager.notify(NOTIF_DOWNLOAD, notification); oldState = newState; } } }); boolean hasReply = client.execute(getMethod, responseHandler); if (hasReply) { if (checkMd5) { URL url = new URL(intent.getData().toString().concat(".md5sum")); InputStream content = (InputStream) url.getContent(); if (content != null) { BufferedReader br = new BufferedReader(new InputStreamReader(content)); String downloadedMD5 = ""; try { downloadedMD5 = br.readLine().split(" ")[0]; } catch (NullPointerException e) { throw new IOException("md5_verification : no sum on server"); } if (!MD5.checkMD5(downloadedMD5, output)) { throw new IOException("md5_verification : incorrect"); } } } PendingIntent pendingIntent = (PendingIntent) intent .getParcelableExtra(EXTRA_PENDING_FINISH_INTENT); try { Runtime.getRuntime().exec("chmod 644 " + outPath); } catch (IOException e) { Log.e(THIS_FILE, "Unable to make the apk file readable", e); } Log.d(THIS_FILE, "Download finished of : " + outPath); if (pendingIntent != null) { notification.contentIntent = pendingIntent; notification.flags = Notification.FLAG_AUTO_CANCEL; notification.icon = android.R.drawable.stat_sys_download_done; notification.contentView.setViewVisibility(R.id.status_progress_wrapper, View.GONE); notification.contentView.setTextViewText(R.id.status_text, getResources().getString(R.string.done) // TODO should be a parameter of this class + " - Click to install"); notificationManager.notify(NOTIF_DOWNLOAD, notification); /* try { pendingIntent.send(); notificationManager.cancel(NOTIF_DOWNLOAD); } catch (CanceledException e) { Log.e(THIS_FILE, "Impossible to start pending intent for download finish"); } */ } else { Log.w(THIS_FILE, "Invalid pending intent for finish !!!"); } result = Activity.RESULT_OK; } } catch (IOException e) { Log.e(THIS_FILE, "Exception in download", e); } } if (result == Activity.RESULT_CANCELED) { notificationManager.cancel(NOTIF_DOWNLOAD); } }
From source file:com.csipsimple.service.Downloader.java
@Override protected void onHandleIntent(Intent intent) { HttpGet getMethod = new HttpGet(intent.getData().toString()); int result = Activity.RESULT_CANCELED; String outPath = intent.getStringExtra(EXTRA_OUTPATH); boolean checkMd5 = intent.getBooleanExtra(EXTRA_CHECK_MD5, false); int icon = intent.getIntExtra(EXTRA_ICON, 0); String title = intent.getStringExtra(EXTRA_TITLE); boolean showNotif = (icon > 0 && !TextUtils.isEmpty(title)); // Build notification Builder nb = new NotificationCompat.Builder(this); nb.setWhen(System.currentTimeMillis()); nb.setContentTitle(title);// w ww . j ava 2 s . com nb.setSmallIcon(android.R.drawable.stat_sys_download); nb.setOngoing(true); Intent i = new Intent(this, SipHome.class); nb.setContentIntent(PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT)); RemoteViews contentView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.download_notif); contentView.setImageViewResource(R.id.status_icon, icon); contentView.setTextViewText(R.id.status_text, getResources().getString(R.string.downloading_text)); contentView.setProgressBar(R.id.status_progress, 50, 0, false); contentView.setViewVisibility(R.id.status_progress_wrapper, View.VISIBLE); nb.setContent(contentView); final Notification notification = showNotif ? nb.build() : null; notification.contentView = contentView; if (!TextUtils.isEmpty(outPath)) { try { File output = new File(outPath); if (output.exists()) { output.delete(); } if (notification != null) { notificationManager.notify(NOTIF_DOWNLOAD, notification); } ResponseHandler<Boolean> responseHandler = new FileStreamResponseHandler(output, new Progress() { private int oldState = 0; @Override public void run(long progress, long total) { //Log.d(THIS_FILE, "Progress is "+progress+" on "+total); int newState = (int) Math.round(progress * 50.0f / total); if (oldState != newState) { notification.contentView.setProgressBar(R.id.status_progress, 50, newState, false); notificationManager.notify(NOTIF_DOWNLOAD, notification); oldState = newState; } } }); boolean hasReply = client.execute(getMethod, responseHandler); if (hasReply) { if (checkMd5) { URL url = new URL(intent.getData().toString().concat(".md5sum")); InputStream content = (InputStream) url.getContent(); if (content != null) { BufferedReader br = new BufferedReader(new InputStreamReader(content)); String downloadedMD5 = ""; try { downloadedMD5 = br.readLine().split(" ")[0]; } catch (NullPointerException e) { throw new IOException("md5_verification : no sum on server"); } if (!MD5.checkMD5(downloadedMD5, output)) { throw new IOException("md5_verification : incorrect"); } } } PendingIntent pendingIntent = (PendingIntent) intent .getParcelableExtra(EXTRA_PENDING_FINISH_INTENT); try { Runtime.getRuntime().exec("chmod 644 " + outPath); } catch (IOException e) { Log.e(THIS_FILE, "Unable to make the apk file readable", e); } Log.d(THIS_FILE, "Download finished of : " + outPath); if (pendingIntent != null) { notification.contentIntent = pendingIntent; notification.flags = Notification.FLAG_AUTO_CANCEL; notification.icon = android.R.drawable.stat_sys_download_done; notification.contentView.setViewVisibility(R.id.status_progress_wrapper, View.GONE); notification.contentView.setTextViewText(R.id.status_text, getResources().getString(R.string.done) // TODO should be a parameter of this class + " - Click to install"); notificationManager.notify(NOTIF_DOWNLOAD, notification); /* try { pendingIntent.send(); notificationManager.cancel(NOTIF_DOWNLOAD); } catch (CanceledException e) { Log.e(THIS_FILE, "Impossible to start pending intent for download finish"); } */ } else { Log.w(THIS_FILE, "Invalid pending intent for finish !!!"); } result = Activity.RESULT_OK; } } catch (IOException e) { Log.e(THIS_FILE, "Exception in download", e); } } if (result == Activity.RESULT_CANCELED) { notificationManager.cancel(NOTIF_DOWNLOAD); } }
From source file:com.sonetel.service.Downloader.java
@Override protected void onHandleIntent(Intent intent) { HttpGet getMethod = new HttpGet(intent.getData().toString()); int result = Activity.RESULT_CANCELED; String outPath = intent.getStringExtra(EXTRA_OUTPATH); boolean checkMd5 = intent.getBooleanExtra(EXTRA_CHECK_MD5, false); int icon = intent.getIntExtra(EXTRA_ICON, 0); String title = intent.getStringExtra(EXTRA_TITLE); boolean showNotif = (icon > 0 && !TextUtils.isEmpty(title)); // Build notification Builder nb = new NotificationCompat.Builder(this); nb.setWhen(System.currentTimeMillis()); nb.setContentTitle(title);//from w w w . ja v a2 s .co m nb.setSmallIcon(android.R.drawable.stat_sys_download); nb.setOngoing(true); Intent i = new Intent(this, SipHome.class); nb.setContentIntent(PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT)); RemoteViews contentView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.download_notif); contentView.setImageViewResource(R.id.status_icon, icon); contentView.setTextViewText(R.id.status_text, getResources().getString(R.string.downloading_text)); contentView.setProgressBar(R.id.status_progress, 50, 0, false); contentView.setViewVisibility(R.id.status_progress_wrapper, View.VISIBLE); nb.setContent(contentView); final Notification notification = showNotif ? nb.getNotification() : null; notification.contentView = contentView; if (!TextUtils.isEmpty(outPath)) { try { File output = new File(outPath); if (output.exists()) { output.delete(); } if (notification != null) { notificationManager.notify(NOTIF_DOWNLOAD, notification); } ResponseHandler<Boolean> responseHandler = new FileStreamResponseHandler(output, new Progress() { private int oldState = 0; @Override public void run(long progress, long total) { //Log.d(THIS_FILE, "Progress is "+progress+" on "+total); int newState = (int) Math.round(progress * 50.0f / total); if (oldState != newState) { notification.contentView.setProgressBar(R.id.status_progress, 50, newState, false); notificationManager.notify(NOTIF_DOWNLOAD, notification); oldState = newState; } } }); boolean hasReply = client.execute(getMethod, responseHandler); if (hasReply) { if (checkMd5) { URL url = new URL(intent.getData().toString().concat(".md5sum")); InputStream content = (InputStream) url.getContent(); if (content != null) { BufferedReader br = new BufferedReader(new InputStreamReader(content)); String downloadedMD5 = ""; try { downloadedMD5 = br.readLine().split(" ")[0]; } catch (NullPointerException e) { throw new IOException("md5_verification : no sum on server"); } if (!MD5.checkMD5(downloadedMD5, output)) { throw new IOException("md5_verification : incorrect"); } } } PendingIntent pendingIntent = (PendingIntent) intent .getParcelableExtra(EXTRA_PENDING_FINISH_INTENT); try { Runtime.getRuntime().exec("chmod 644 " + outPath); } catch (IOException e) { Log.e(THIS_FILE, "Unable to make the apk file readable", e); } Log.d(THIS_FILE, "Download finished of : " + outPath); if (pendingIntent != null) { notification.contentIntent = pendingIntent; notification.flags = Notification.FLAG_AUTO_CANCEL; notification.icon = android.R.drawable.stat_sys_download_done; notification.contentView.setViewVisibility(R.id.status_progress_wrapper, View.GONE); notification.contentView.setTextViewText(R.id.status_text, getResources().getString(R.string.done) // TODO should be a parameter of this class + " - Click to install"); notificationManager.notify(NOTIF_DOWNLOAD, notification); /* try { pendingIntent.send(); notificationManager.cancel(NOTIF_DOWNLOAD); } catch (CanceledException e) { Log.e(THIS_FILE, "Impossible to start pending intent for download finish"); } */ } else { Log.w(THIS_FILE, "Invalid pending intent for finish !!!"); } result = Activity.RESULT_OK; } } catch (IOException e) { Log.e(THIS_FILE, "Exception in download", e); } } if (result == Activity.RESULT_CANCELED) { notificationManager.cancel(NOTIF_DOWNLOAD); } }