Java Code Examples for android.app.DownloadManager#ACTION_VIEW_DOWNLOADS

The following examples show how to use android.app.DownloadManager#ACTION_VIEW_DOWNLOADS . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AdBlocksWebViewActivity.java    From AdBlockedWebView-Android with MIT License 6 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();

    if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
        if (mDownloadManager != null) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                Uri downloadedUri = mDownloadManager.getUriForDownloadedFile(mLastDownloadId);
                String mimeType = mDownloadManager.getMimeTypeForDownloadedFile(mLastDownloadId);

                new NotifyDownloadedTask().execute(downloadedUri.toString(), mimeType);
            }
        }
    } else if (DownloadManager.ACTION_NOTIFICATION_CLICKED.equals(action)) {
        Intent notiIntent = new Intent(DownloadManager.ACTION_VIEW_DOWNLOADS);
        notiIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(notiIntent);
    }
}
 
Example 2
Source File: ApkInstallReceiver.java    From AndroidUpdater with Apache License 2.0 6 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(intent.getAction())) {
        long downloadApkId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1);
        long localDownloadId = UpdaterUtils.getLocalDownloadId(context);
        if (downloadApkId == localDownloadId) {
            Logger.get().d("download complete. downloadId is " + downloadApkId);
            installApk(context, downloadApkId);
        }
    } else if (DownloadManager.ACTION_NOTIFICATION_CLICKED.equals(intent.getAction())) {
        //处理 如果还未完成下载,用户点击Notification
        Intent viewDownloadIntent = new Intent(DownloadManager.ACTION_VIEW_DOWNLOADS);
        viewDownloadIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(viewDownloadIntent);
    }
}
 
Example 3
Source File: DownloadManagerService.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Open the Activity which shows a list of all downloads.
 * @param context Application context
 */
protected static void openDownloadsPage(Context context) {
    Intent pageView = new Intent(DownloadManager.ACTION_VIEW_DOWNLOADS);
    pageView.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    try {
        context.startActivity(pageView);
    } catch (ActivityNotFoundException e) {
        Log.e(TAG, "Cannot find Downloads app", e);
    }
}
 
Example 4
Source File: IntentHelper.java    From zapp with MIT License 5 votes vote down vote up
/**
 * Open the download manager app. If no app is found that can handle
 * this intent, a a system chooser is shown.
 *
 * @param context
 */
public static void openDownloadManager(Context context) {
	Intent downloadManagerIntent = new Intent(DownloadManager.ACTION_VIEW_DOWNLOADS);
	downloadManagerIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

	try {
		context.startActivity(downloadManagerIntent);
	} catch (ActivityNotFoundException e) {
		context.startActivity(Intent.createChooser(downloadManagerIntent, context.getString(R.string.action_open)));
	}
}
 
Example 5
Source File: DownloadManagerService.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Open the Activity which shows a list of all downloads.
 * @param context Application context
 */
protected static void openDownloadsPage(Context context) {
    if (DownloadUtils.showDownloadManager(null, null)) return;

    // Open the Android Download Manager.
    Intent pageView = new Intent(DownloadManager.ACTION_VIEW_DOWNLOADS);
    pageView.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    try {
        context.startActivity(pageView);
    } catch (ActivityNotFoundException e) {
        Log.e(TAG, "Cannot find Downloads app", e);
    }
}
 
Example 6
Source File: DownloadManagerService.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Open the Activity which shows a list of all downloads.
 * @param context Application context
 */
public static void openDownloadsPage(Context context) {
    if (DownloadUtils.showDownloadManager(null, null)) return;

    // Open the Android Download Manager.
    Intent pageView = new Intent(DownloadManager.ACTION_VIEW_DOWNLOADS);
    pageView.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    try {
        context.startActivity(pageView);
    } catch (ActivityNotFoundException e) {
        Log.e(TAG, "Cannot find Downloads app", e);
    }
}
 
Example 7
Source File: ExportService.java    From science-journal with Apache License 2.0 4 votes vote down vote up
@TargetApi(VERSION_CODES.O)
private static void copyToDownload(
    Context context, Uri sourceUri, String fileName, File destination) {
  try {
    if (AndroidVersionUtils.isApiLevelAtLeastOreo()) {
      Files.copy(
          context.getContentResolver().openInputStream(sourceUri),
          destination.toPath(),
          StandardCopyOption.REPLACE_EXISTING);
    } else {
      UpdateExperimentFragment.copyUriToFile(context, sourceUri, destination);
      // Inform DownloadManager of completed download so the file shows in Downloads app
      DownloadManager downloadManager =
          (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
      downloadManager.addCompletedDownload(
          destination.getName(),
          destination.getName(),
          true,
          getMimeTypeFromFileName(fileName),
          destination.getAbsolutePath(),
          destination.length(),
          false);
    }
    Intent intent = new Intent(DownloadManager.ACTION_VIEW_DOWNLOADS);
    PendingIntent pendingIntent =
        PendingIntent.getActivity(context, 1, intent, PendingIntent.FLAG_ONE_SHOT);
    ((NotificationManager)
            context.getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE))
        .notify(
            NotificationIds.SAVED_TO_DEVICE,
            new NotificationCompat.Builder(
                    context.getApplicationContext(), NotificationChannels.SAVE_TO_DEVICE_CHANNEL)
                .setContentTitle(fileName)
                .setContentText(context.getString(R.string.saved_to_device_text))
                .setSubText(context.getString(R.string.save_to_device_channel_description))
                .setSmallIcon(R.drawable.ic_notification_24dp)
                .setContentIntent(pendingIntent)
                .setAutoCancel(true)
                .build());
  } catch (IOException ioe) {
    AppSingleton.getInstance(context)
        .onNextActivity()
        .subscribe(
            activity -> {
              AccessibilityUtils.makeSnackbar(
                      activity.findViewById(android.R.id.content),
                      context.getResources().getString(R.string.saved_to_device_error),
                      Snackbar.LENGTH_SHORT)
                  .show();
            });
    ioe.printStackTrace();
    if (destination.exists()) {
      destination.delete();
    }
  } finally {
    AppSingleton.getInstance(context).setExportServiceBusy(false);
  }
}