List of usage examples for android.app DownloadManager ACTION_NOTIFICATION_CLICKED
String ACTION_NOTIFICATION_CLICKED
To view the source code for android.app DownloadManager ACTION_NOTIFICATION_CLICKED.
Click Source Link
From source file:com.commonsware.android.downmgr.DownloadFragment.java
@Override public void onResume() { super.onResume(); IntentFilter f = new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE); f.addAction(DownloadManager.ACTION_NOTIFICATION_CLICKED); getActivity().registerReceiver(onEvent, f); }
From source file:com.tenmiles.helpstack.service.AttachmentDownloadReceiver.java
@Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); String package_name = intent.getPackage(); String cpackage = context.getPackageName(); if (package_name.equals(cpackage) && DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) { downloadCompleted(context, intent); } else if (package_name.equals(cpackage) && DownloadManager.ACTION_NOTIFICATION_CLICKED.equals(action)) { notificationClicked(context, intent); }//from w w w . j av a2 s.c o m }
From source file:es.usc.citius.servando.calendula.fragments.MedicinesListFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getActivity().registerReceiver(onComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); getActivity().registerReceiver(onNotificationClick, new IntentFilter(DownloadManager.ACTION_NOTIFICATION_CLICKED)); }
From source file:com.tfc.webviewer.ui.WebViewerActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); //noinspection ConstantConditions getSupportActionBar().hide();// ww w . java2 s . c o m IntentFilter filter = new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE); filter.addAction(DownloadManager.ACTION_NOTIFICATION_CLICKED); registerReceiver(mDownloadReceiver, filter); mUrl = getIntent().getStringExtra(EXTRA_URL); setContentView(R.layout.a_web_viewer); bindView(); mPresenter = new WebViewPresenterImpl(this, this); mPresenter.validateUrl(mUrl); }
From source file:com.otaupdater.DownloadReceiver.java
@Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action == null) return;/*from w w w . j ava 2 s . c o m*/ if (action.equals(DL_ROM_ACTION)) { RomInfo.FACTORY.clearUpdateNotif(context); RomInfo.FACTORY.fromIntent(intent).startDownload(context); } else if (action.equals(DL_KERNEL_ACTION)) { KernelInfo.FACTORY.clearUpdateNotif(context); KernelInfo.FACTORY.fromIntent(intent).startDownload(context); } else if (action.equals(CLEAR_DL_ACTION)) { if (intent.hasExtra(DownloadManager.EXTRA_DOWNLOAD_ID)) { DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE); dm.remove(intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1)); DownloadBarFragment.notifyActiveFragment(); } } else if (action.equals(DownloadManager.ACTION_DOWNLOAD_COMPLETE)) { DownloadStatus status = DownloadStatus.forDownloadID(context, intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1)); if (status == null) return; BaseInfo info = status.getInfo(); if (info == null) return; int error = status.getStatus() == DownloadManager.STATUS_SUCCESSFUL ? info.checkDownloadedFile() : status.getReason(); NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); if (error == 0) { Intent mainIntent = new Intent(context, OTAUpdaterActivity.class); mainIntent.setAction(info.getNotifAction()); mainIntent.putExtra(OTAUpdaterActivity.EXTRA_FLAG_DOWNLOAD_DIALOG, true); PendingIntent mainPIntent = PendingIntent.getActivity(context, 0, mainIntent, PendingIntent.FLAG_CANCEL_CURRENT); Intent flashIntent = new Intent(context, DownloadsActivity.class); flashIntent.setAction(info.getFlashAction()); info.addToIntent(flashIntent); PendingIntent flashPIntent = PendingIntent.getActivity(context, 0, flashIntent, PendingIntent.FLAG_CANCEL_CURRENT); Notification notif = new NotificationCompat.Builder(context) .setTicker(context.getString(info.getDownloadDoneTitle())) .setContentTitle(context.getString(info.getDownloadDoneTitle())) .setSmallIcon(R.drawable.ic_stat_av_download) .setContentText(context.getString(R.string.notif_completed)).setContentIntent(mainPIntent) .addAction(R.drawable.ic_action_system_update, context.getString(R.string.install), flashPIntent) .build(); nm.notify(info.getFlashNotifID(), notif); } else { Intent mainIntent = new Intent(context, OTAUpdaterActivity.class); mainIntent.setAction(info.getNotifAction()); info.addToIntent(mainIntent); PendingIntent mainPIntent = PendingIntent.getActivity(context, 0, mainIntent, PendingIntent.FLAG_CANCEL_CURRENT); Intent dlIntent = new Intent(context, DownloadReceiver.class); dlIntent.setAction(info.getDownloadAction()); info.addToIntent(dlIntent); PendingIntent dlPIntent = PendingIntent.getBroadcast(context, 1, dlIntent, PendingIntent.FLAG_CANCEL_CURRENT); Intent clearIntent = new Intent(context, DownloadReceiver.class); clearIntent.setAction(CLEAR_DL_ACTION); clearIntent.putExtra(DownloadManager.EXTRA_DOWNLOAD_ID, status.getId()); PendingIntent clearPIntent = PendingIntent.getBroadcast(context, 2, clearIntent, PendingIntent.FLAG_CANCEL_CURRENT); Notification notif = new NotificationCompat.Builder(context) .setTicker(context.getString(info.getDownloadFailedTitle())) .setContentTitle(context.getString(info.getDownloadFailedTitle())) .setContentText(status.getErrorString(context)).setSmallIcon(R.drawable.ic_stat_warning) .setContentIntent(mainPIntent).setDeleteIntent(clearPIntent) .addAction(R.drawable.ic_action_refresh, context.getString(R.string.retry), dlPIntent) .build(); nm.notify(info.getFailedNotifID(), notif); } } else if (action.equals(DownloadManager.ACTION_NOTIFICATION_CLICKED)) { long[] ids = intent.getLongArrayExtra(DownloadManager.EXTRA_NOTIFICATION_CLICK_DOWNLOAD_IDS); if (ids.length == 0) return; DownloadStatus status = DownloadStatus.forDownloadID(context, ids[0]); if (status == null) return; BaseInfo info = status.getInfo(); if (info == null) return; Intent i = new Intent(context, OTAUpdaterActivity.class); i.setAction(info.getNotifAction()); i.putExtra(OTAUpdaterActivity.EXTRA_FLAG_DOWNLOAD_DIALOG, true); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i); } }
From source file:com.nks.nksmod.otaupdater.DownloadReceiver.java
@Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action == null) return;//ww w . j av a 2 s.c o m if (action.equals(DL_ROM_ACTION)) { RomInfo.FACTORY.clearUpdateNotif(context); RomInfo.FACTORY.fromIntent(intent).startDownload(context); /* } else if (action.equals(DL_KERNEL_ACTION)) { KernelInfo.FACTORY.clearUpdateNotif(context); KernelInfo.FACTORY.fromIntent(intent).startDownload(context); */ } else if (action.equals(CLEAR_DL_ACTION)) { if (intent.hasExtra(DownloadManager.EXTRA_DOWNLOAD_ID)) { DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE); dm.remove(intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1)); DownloadBarFragment.notifyActiveFragment(); } } else if (action.equals(DownloadManager.ACTION_DOWNLOAD_COMPLETE)) { DownloadStatus status = DownloadStatus.forDownloadID(context, intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1)); if (status == null) return; BaseInfo info = status.getInfo(); if (info == null) return; int error = status.getStatus() == DownloadManager.STATUS_SUCCESSFUL ? info.checkDownloadedFile() : status.getReason(); NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); if (error == 0) { Intent mainIntent = new Intent(context, OTAUpdaterActivity.class); mainIntent.setAction(info.getNotifAction()); mainIntent.putExtra(OTAUpdaterActivity.EXTRA_FLAG_DOWNLOAD_DIALOG, true); PendingIntent mainPIntent = PendingIntent.getActivity(context, 0, mainIntent, PendingIntent.FLAG_CANCEL_CURRENT); Intent flashIntent = new Intent(context, DownloadsActivity.class); flashIntent.setAction(info.getFlashAction()); info.addToIntent(flashIntent); PendingIntent flashPIntent = PendingIntent.getActivity(context, 0, flashIntent, PendingIntent.FLAG_CANCEL_CURRENT); Notification notif = new NotificationCompat.Builder(context) .setTicker(context.getString(info.getDownloadDoneTitle())) .setContentTitle(context.getString(info.getDownloadDoneTitle())) .setSmallIcon(R.drawable.ic_stat_av_download) .setContentText(context.getString(R.string.notif_completed)).setContentIntent(mainPIntent) .addAction(R.drawable.ic_action_system_update, context.getString(R.string.install), flashPIntent) .build(); nm.notify(info.getFlashNotifID(), notif); } else { Intent mainIntent = new Intent(context, OTAUpdaterActivity.class); mainIntent.setAction(info.getNotifAction()); info.addToIntent(mainIntent); PendingIntent mainPIntent = PendingIntent.getActivity(context, 0, mainIntent, PendingIntent.FLAG_CANCEL_CURRENT); Intent dlIntent = new Intent(context, DownloadReceiver.class); dlIntent.setAction(info.getDownloadAction()); info.addToIntent(dlIntent); PendingIntent dlPIntent = PendingIntent.getBroadcast(context, 1, dlIntent, PendingIntent.FLAG_CANCEL_CURRENT); Intent clearIntent = new Intent(context, DownloadReceiver.class); clearIntent.setAction(CLEAR_DL_ACTION); clearIntent.putExtra(DownloadManager.EXTRA_DOWNLOAD_ID, status.getId()); PendingIntent clearPIntent = PendingIntent.getBroadcast(context, 2, clearIntent, PendingIntent.FLAG_CANCEL_CURRENT); Notification notif = new NotificationCompat.Builder(context) .setTicker(context.getString(info.getDownloadFailedTitle())) .setContentTitle(context.getString(info.getDownloadFailedTitle())) .setContentText(status.getErrorString(context)).setSmallIcon(R.drawable.ic_stat_warning) .setContentIntent(mainPIntent).setDeleteIntent(clearPIntent) .addAction(R.drawable.ic_action_refresh, context.getString(R.string.retry), dlPIntent) .build(); nm.notify(info.getFailedNotifID(), notif); } } else if (action.equals(DownloadManager.ACTION_NOTIFICATION_CLICKED)) { long[] ids = intent.getLongArrayExtra(DownloadManager.EXTRA_NOTIFICATION_CLICK_DOWNLOAD_IDS); if (ids.length == 0) return; DownloadStatus status = DownloadStatus.forDownloadID(context, ids[0]); if (status == null) return; BaseInfo info = status.getInfo(); if (info == null) return; Intent i = new Intent(context, OTAUpdaterActivity.class); i.setAction(info.getNotifAction()); i.putExtra(OTAUpdaterActivity.EXTRA_FLAG_DOWNLOAD_DIALOG, true); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i); } }
From source file:com.ota.updates.receivers.AppReceiver.java
@Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); Bundle extras = intent.getExtras();//from w w w .j av a 2s . co m long mRomDownloadID = Preferences.getDownloadID(context); if (action.equals(DownloadManager.ACTION_DOWNLOAD_COMPLETE)) { long id = extras.getLong(DownloadManager.EXTRA_DOWNLOAD_ID); boolean isAddonDownload = false; int keyForAddonDownload = 0; Set<Integer> set = OtaUpdates.getAddonDownloadKeySet(); Iterator<Integer> iterator = set.iterator(); while (iterator.hasNext() && isAddonDownload != true) { int nextValue = iterator.next(); if (id == OtaUpdates.getAddonDownload(nextValue)) { isAddonDownload = true; keyForAddonDownload = nextValue; if (DEBUGGING) { Log.d(TAG, "Checking ID " + nextValue); } } } if (isAddonDownload) { DownloadManager downloadManager = (DownloadManager) context .getSystemService(Context.DOWNLOAD_SERVICE); DownloadManager.Query query = new DownloadManager.Query(); query.setFilterById(id); Cursor cursor = downloadManager.query(query); // it shouldn't be empty, but just in case if (!cursor.moveToFirst()) { if (DEBUGGING) Log.e(TAG, "Addon Download Empty row"); return; } int statusIndex = cursor.getColumnIndex(DownloadManager.COLUMN_STATUS); if (DownloadManager.STATUS_SUCCESSFUL != cursor.getInt(statusIndex)) { if (DEBUGGING) Log.w(TAG, "Download Failed"); Log.d(TAG, "Removing Addon download with id " + keyForAddonDownload); OtaUpdates.removeAddonDownload(keyForAddonDownload); AddonActivity.AddonsArrayAdapter.updateProgress(keyForAddonDownload, 0, true); AddonActivity.AddonsArrayAdapter.updateButtons(keyForAddonDownload, false); return; } else { if (DEBUGGING) Log.v(TAG, "Download Succeeded"); Log.d(TAG, "Removing Addon download with id " + keyForAddonDownload); OtaUpdates.removeAddonDownload(keyForAddonDownload); AddonActivity.AddonsArrayAdapter.updateButtons(keyForAddonDownload, true); return; } } else { if (DEBUGGING) Log.v(TAG, "Receiving " + mRomDownloadID); if (id != mRomDownloadID) { if (DEBUGGING) Log.v(TAG, "Ignoring unrelated non-ROM download " + id); return; } DownloadManager downloadManager = (DownloadManager) context .getSystemService(Context.DOWNLOAD_SERVICE); DownloadManager.Query query = new DownloadManager.Query(); query.setFilterById(id); Cursor cursor = downloadManager.query(query); // it shouldn't be empty, but just in case if (!cursor.moveToFirst()) { if (DEBUGGING) Log.e(TAG, "Rom download Empty row"); return; } int statusIndex = cursor.getColumnIndex(DownloadManager.COLUMN_STATUS); if (DownloadManager.STATUS_SUCCESSFUL != cursor.getInt(statusIndex)) { if (DEBUGGING) Log.w(TAG, "Download Failed"); Preferences.setDownloadFinished(context, false); if (Utils.isLollipop()) { AvailableActivity.setupMenuToolbar(context); // Reset options menu } else { AvailableActivity.invalidateMenu(); } return; } else { if (DEBUGGING) Log.v(TAG, "Download Succeeded"); Preferences.setDownloadFinished(context, true); AvailableActivity.setupProgress(context); if (Utils.isLollipop()) { AvailableActivity.setupMenuToolbar(context); // Reset options menu } else { AvailableActivity.invalidateMenu(); } return; } } } if (action.equals(DownloadManager.ACTION_NOTIFICATION_CLICKED)) { long[] ids = extras.getLongArray(DownloadManager.EXTRA_NOTIFICATION_CLICK_DOWNLOAD_IDS); for (long id : ids) { if (id != mRomDownloadID) { if (DEBUGGING) Log.v(TAG, "mDownloadID is " + mRomDownloadID + " and ID is " + id); return; } else { Intent i = new Intent(context, AvailableActivity.class); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i); } } } if (action.equals(MANIFEST_CHECK_BACKGROUND)) { if (DEBUGGING) Log.d(TAG, "Receiving background check confirmation"); boolean updateAvailable = RomUpdate.getUpdateAvailability(context); String filename = RomUpdate.getFilename(context); if (updateAvailable) { Utils.setupNotification(context, filename); Utils.scheduleNotification(context, !Preferences.getBackgroundService(context)); } } if (action.equals(START_UPDATE_CHECK)) { if (DEBUGGING) Log.d(TAG, "Update check started"); new LoadUpdateManifest(context, false).execute(); } if (action.equals(Intent.ACTION_BOOT_COMPLETED)) { if (DEBUGGING) { Log.d(TAG, "Boot received"); } boolean backgroundCheck = Preferences.getBackgroundService(context); if (backgroundCheck) { if (DEBUGGING) Log.d(TAG, "Starting background check alarm"); Utils.scheduleNotification(context, !Preferences.getBackgroundService(context)); } } if (action.equals(IGNORE_RELEASE)) { if (DEBUGGING) { Log.d(TAG, "Ignore release"); } Preferences.setIgnoredRelease(context, Integer.toString(RomUpdate.getVersionNumber(context))); final NotificationManager mNotifyManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Builder mBuilder = new NotificationCompat.Builder(context); mBuilder.setContentTitle(context.getString(R.string.main_release_ignored)) .setSmallIcon(R.drawable.ic_notif) .setContentIntent(PendingIntent.getActivity(context, 0, new Intent(), 0)); mNotifyManager.notify(NOTIFICATION_ID, mBuilder.build()); Handler h = new Handler(); long delayInMilliseconds = 1500; h.postDelayed(new Runnable() { public void run() { mNotifyManager.cancel(NOTIFICATION_ID); } }, delayInMilliseconds); } }
From source file:org.chromium.chrome.browser.download.DownloadNotificationService.java
/** * Add a download successful notification. * @param downloadGuid GUID of the download. * @param filePath Full path to the download. * @param fileName Filename of the download. * @param systemDownloadId Download ID assigned by system DownloadManager. * @param isOfflinePage Whether the download is for offline page. * @param isSupportedMimeType Whether the MIME type can be viewed inside browser. * @return ID of the successful download notification. Used for removing the notification when * user click on the snackbar.//from w w w . j a va 2s. com */ public int notifyDownloadSuccessful(String downloadGuid, String filePath, String fileName, long systemDownloadId, boolean isOfflinePage, boolean isSupportedMimeType) { int notificationId = getNotificationId(downloadGuid); NotificationCompat.Builder builder = buildNotification(R.drawable.offline_pin, fileName, mContext.getResources().getString(R.string.download_notification_completed)); ComponentName component = new ComponentName(mContext.getPackageName(), DownloadBroadcastReceiver.class.getName()); Intent intent; if (isOfflinePage) { intent = buildActionIntent(ACTION_DOWNLOAD_OPEN, notificationId, downloadGuid, fileName, isOfflinePage); } else { intent = new Intent(DownloadManager.ACTION_NOTIFICATION_CLICKED); long[] idArray = { systemDownloadId }; intent.putExtra(DownloadManager.EXTRA_NOTIFICATION_CLICK_DOWNLOAD_IDS, idArray); intent.putExtra(EXTRA_DOWNLOAD_FILE_PATH, filePath); intent.putExtra(EXTRA_IS_SUPPORTED_MIME_TYPE, isSupportedMimeType); } intent.setComponent(component); builder.setContentIntent( PendingIntent.getBroadcast(mContext, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT)); if (mDownloadSuccessLargeIcon == null) { Bitmap bitmap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.offline_pin); mDownloadSuccessLargeIcon = getLargeNotificationIcon(bitmap); } builder.setLargeIcon(mDownloadSuccessLargeIcon); updateNotification(notificationId, builder.build()); removeSharedPreferenceEntry(downloadGuid); mDownloadsInProgress.remove(downloadGuid); return notificationId; }
From source file:scal.io.liger.LigerDownloadManager.java
private synchronized void initReceivers() { String fileName = ZipHelper.getExpansionZipFilename(context, mainOrPatch, version); FilteredBroadcastReceiver onComplete = new FilteredBroadcastReceiver(fileName); BroadcastReceiver onNotificationClick = new BroadcastReceiver() { public void onReceive(Context context, Intent intent) { // ??? }// w ww . j a v a 2s . c om }; context.registerReceiver(onComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); context.registerReceiver(onNotificationClick, new IntentFilter(DownloadManager.ACTION_NOTIFICATION_CLICKED)); }