如何在Android中为通知中的下载处理添加取消功能?
我有这个代码供下载经理下载 代码: 下载类别:如何在Android中为通知中的下载处理添加取消功能?,android,download,android-download-manager,request-cancelling,Android,Download,Android Download Manager,Request Cancelling,我有这个代码供下载经理下载 代码: 下载类别: public static boolean isDownloadManagerAvailable(Context context) { try { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) { return false; } Intent int
public static boolean isDownloadManagerAvailable(Context context) {
try {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) {
return false;
}
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setClassName("com.android.providers.downloads.ui", "com.android.providers.downloads.ui.DownloadList");
List<ResolveInfo> list = context.getPackageManager().queryIntentActivities(intent,
PackageManager.MATCH_DEFAULT_ONLY);
return list.size() > 0;
} catch (Exception e) {
return false;
}
}
现在我想在通知中单击下载处理时,取消当前下载。如果要取消下载通知的下载操作,则需要使用自定义通知而不是内置通知。 或者,当用户在通知中单击时,您可以通过取消操作打开下载列表
您可以阅读有关下载管理器单击操作的更多信息请注意,一些三星Galaxy设备(如S5和S6)在isDownloadManagerAvailable调用中返回false。我说的是我的经验,了解DownloadManager是否可用的最好方法就是检查android版本是否高于或等于Gingerbread。
public static boolean isDownloadManagerAvailable(Context context) {
try {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) {
return false;
}
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setClassName("com.android.providers.downloads.ui", "com.android.providers.downloads.ui.DownloadList");
List<ResolveInfo> list = context.getPackageManager().queryIntentActivities(intent,
PackageManager.MATCH_DEFAULT_ONLY);
return list.size() > 0;
} catch (Exception e) {
return false;
}
}