1

我正在尝试以这种方式使用 Android DownloadManager 类: super.onCreate(savedInstanceState); 设置内容视图(R.layout.main);

Request r = new Request(Uri.parse("http://url"));
r.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "file.ext"); // also tried all other possible ways to set up destination
DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
dm.enqueue(r);

在最后一行,dm.enqueue(r)应用程序崩溃了。日志错误:

05-12 13:53:55.408: E/JavaBinder(6814): *** Uncaught remote exception!  (Exceptions are not yet supported across processes.)
05-12 13:53:55.408: E/JavaBinder(6814): java.lang.NoSuchMethodError: getExternalStorages
05-12 13:53:55.408: E/JavaBinder(6814):     at com.android.providers.downloads.Helpers.isFilenameValid(Helpers.java:652)
05-12 13:53:55.408: E/JavaBinder(6814):     at com.android.providers.downloads.DownloadProvider.checkFileUriDestination(DownloadProvider.java:613)
05-12 13:53:55.408: E/JavaBinder(6814):     at com.android.providers.downloads.DownloadProvider.insert(DownloadProvider.java:500)
05-12 13:53:55.408: E/JavaBinder(6814):     at android.content.ContentProvider$Transport.insert(ContentProvider.java:198)
05-12 13:53:55.408: E/JavaBinder(6814):     at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:146)
05-12 13:53:55.408: E/JavaBinder(6814):     at android.os.Binder.execTransact(Binder.java:324)
05-12 13:53:55.408: E/JavaBinder(6814):     at dalvik.system.NativeStart.run(Native Method)
05-12 13:53:55.408: W/dalvikvm(6814): threadid=7: thread exiting with uncaught exception (group=0x2aac8620)
05-12 13:53:55.408: E/AndroidRuntime(6814): FATAL EXCEPTION: Binder Thread #1
05-12 13:53:55.408: E/AndroidRuntime(6814): java.lang.NoSuchMethodError: getExternalStorages
05-12 13:53:55.408: E/AndroidRuntime(6814):     at com.android.providers.downloads.Helpers.isFilenameValid(Helpers.java:652)
05-12 13:53:55.408: E/AndroidRuntime(6814):     at com.android.providers.downloads.DownloadProvider.checkFileUriDestination(DownloadProvider.java:613)
05-12 13:53:55.408: E/AndroidRuntime(6814):     at com.android.providers.downloads.DownloadProvider.insert(DownloadProvider.java:500)
05-12 13:53:55.408: E/AndroidRuntime(6814):     at android.content.ContentProvider$Transport.insert(ContentProvider.java:198)
05-12 13:53:55.408: E/AndroidRuntime(6814):     at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:146)
05-12 13:53:55.408: E/AndroidRuntime(6814):     at android.os.Binder.execTransact(Binder.java:324)
05-12 13:53:55.408: E/AndroidRuntime(6814):     at dalvik.system.NativeStart.run(Native Method)

但是,如果我不以任何方式指定目的地,则文件已成功下载。

我完全不明白有什么问题。请问你能帮帮我吗?

4

1 回答 1

1

在模拟器(或其他未修改的环境)上尝试您的代码。您也可以考虑尝试使用已知的工作代码

于 2012-05-20T00:20:59.330 回答