【发布时间】:2019-06-14 21:58:53
【问题描述】:
我正在下载一个 pdf 文件,下载通知在 marshmallow 中可见,但在 Android P 中不可见。
我的文件在 Android-M 和 Android-P 中均成功下载
我的代码在这里。
public static long DownloadData (Uri uri, Context context,String dir,String fileName,String title,String discription) {
if(title==null){
title="";
}
if(discription==null){
discription="";
}
long downloadReference;
final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
// Create request for android download manager
downloadManager = (DownloadManager)context.getSystemService(DOWNLOAD_SERVICE);
DownloadManager.Request request = new DownloadManager.Request(uri);
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE);
request.setVisibleInDownloadsUi (true);
request.setNotificationVisibility (DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.addRequestHeader("Authorization", "Bearer " + sp.getString(SharedPreferenceKeys.PREF_AUTH_TOKEN, "Woof"));
//Setting title of request
request.setTitle(title);
//Setting description of request
request.setDescription(discription);
request.setDestinationInExternalPublicDir(
dir,fileName);
//Enqueue download and save into referenceId
downloadReference = downloadManager.enqueue(request);
return downloadReference;
}
谁能给出在 Android P 中显示下载通知的解决方案?谢谢。
【问题讨论】:
标签: android notifications android-notifications android-download-manager download-manager