DownloadManager.Request.setNotificationVisibility失败,jSecurityException:能见度无效值:1 [英] DownloadManager.Request.setNotificationVisibility fails with jSecurityException: invalid value for visibility: 1
问题描述
我试图使用下载管理器
从我的应用程序下载较大的PDF文件。我想在下载过程中显示通知,以及当下载完成的。但是设置例外上面的可见性的原因。
I am trying to use the DownloadManager
to download large PDF files from my app. I want notifications to be displayed during the download as well as when the download finishes. However setting the visibility causes above exception.
此错误是从这个帖子<不同href=\"http://stackoverflow.com/questions/9345977/downloadmanager-request-setnotificationvisibility-fails-with-jsecurityexception\">DownloadManager.Request.setNotificationVisibility失败jSecurityException:无效值能见度:2
设置能见度 VISIBILITY_HIDDEN
在您需要的权限在清单时,其他职位是寻求帮助。我想设置能见度 DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED
像这样:
The other post is asking for help when setting the visibility to VISIBILITY_HIDDEN
for which you need permission in the manifest. I am trying to set the visibility to DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED
like so:
public class DMnotifyTestActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
DownloadManager mgr = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
long downloadID = mgr
.enqueue(new DownloadManager.Request(Uri.parse("http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/pdf_reference_1-7.pdf"))
.setNotificationVisibility(
DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "hello.pdf")
.setDescription("my.test.pack Doc"));
}
}
这将导致该堆栈跟踪:
E/AndroidRuntime(24794): Caused by: java.lang.SecurityException: Invalid value for visibility: 1
E/AndroidRuntime(24794): at android.os.Parcel.readException(Parcel.java:1321)
E/AndroidRuntime(24794): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:182)
E/AndroidRuntime(24794): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:136)
E/AndroidRuntime(24794): at android.content.ContentProviderProxy.insert(ContentProviderNative.java:447)
E/AndroidRuntime(24794): at android.content.ContentResolver.insert(ContentResolver.java:721)
E/AndroidRuntime(24794): at android.app.DownloadManager.enqueue(DownloadManager.java:877)
E/AndroidRuntime(24794): at my.test.pack.DMnotifyTestActivity.onCreate(DMnotifyTestActivity.java:18)
如果不设置知名度code正常工作。我已经尝试添加各种权限清单,但仍然没有去。这是针对11级所以蜂窝了。我曾尝试权限是:
Without setting visibility the code works fine. I have already attempted adding various permissions to the manifest, but still no go. This is targeting level 11 so honeycomb and up. Permissions I have tried are:
- android.permission.DOWNLOAD_WITHOUT_NOTIFICATION
- android.permission.SEND_DOWNLOAD_COMPLETED_INTENTS
- android.permission.ACCESS_DOWNLOAD_MANAGER
- android.permission.ACCESS_DOWNLOAD_MANAGER_ADVANCED
推荐答案
下面是我砍来克服蜂窝片这个bug(版本:13:3.2或API级别):
Here's my hack to overcome this bug in Honeycomb tablets (Version: 3.2 or API Level: 13):
Request req = new Request(Uri.parse(url));
if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.HONEYCOMB_MR2)
{
req.setNotificationVisibility(Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
}
else
{
req.setNotificationVisibility(Request.VISIBILITY_VISIBLE);
}
啊......与Android的乐趣!
Ah... the fun with Android!
这篇关于DownloadManager.Request.setNotificationVisibility失败,jSecurityException:能见度无效值:1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!