gpt4 book ai didi

Android:运行时错误 'Unable to create directory',使用类 DownloadManager,方法 setDestinationInExternalPublicDir

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:09:45 25 4
gpt4 key购买 nike

我遇到了这个异常:

10-24 17:08:19.711: E/AndroidRuntime(1379): FATAL EXCEPTION: main
10-24 17:08:19.711: E/AndroidRuntime(1379): java.lang.RuntimeException: Unable to start activity ComponentInfo{br.com.campusfqm.cfqm/br.com.campusfqm.cfqm.DownloadManagerActivity}: java.lang.IllegalStateException: Unable to create directory: /mnt/sdcard/Download
10-24 17:08:19.711: E/AndroidRuntime(1379): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1736)
10-24 17:08:19.711: E/AndroidRuntime(1379): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1752)
10-24 17:08:19.711: E/AndroidRuntime(1379): at android.app.ActivityThread.access$1500(ActivityThread.java:123)
10-24 17:08:19.711: E/AndroidRuntime(1379): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:993)
10-24 17:08:19.711: E/AndroidRuntime(1379): at android.os.Handler.dispatchMessage(Handler.java:99)
10-24 17:08:19.711: E/AndroidRuntime(1379): at android.os.Looper.loop(Looper.java:126)
10-24 17:08:19.711: E/AndroidRuntime(1379): at android.app.ActivityThread.main(ActivityThread.java:3997)
10-24 17:08:19.711: E/AndroidRuntime(1379): at java.lang.reflect.Method.invokeNative(Native Method)
10-24 17:08:19.711: E/AndroidRuntime(1379): at java.lang.reflect.Method.invoke(Method.java:491)
10-24 17:08:19.711: E/AndroidRuntime(1379): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
10-24 17:08:19.711: E/AndroidRuntime(1379): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
10-24 17:08:19.711: E/AndroidRuntime(1379): at dalvik.system.NativeStart.main(Native Method)
10-24 17:08:19.711: E/AndroidRuntime(1379): Caused by: java.lang.IllegalStateException: Unable to create directory: /mnt/sdcard/Download
10-24 17:08:19.711: E/AndroidRuntime(1379): at android.app.DownloadManager$Request.setDestinationInExternalPublicDir(DownloadManager.java:466)
10-24 17:08:19.711: E/AndroidRuntime(1379): at br.com.campusfqm.cfqm.DownloadManagerActivity.download(DownloadManagerActivity.java:51)
10-24 17:08:19.711: E/AndroidRuntime(1379): at br.com.campusfqm.cfqm.DownloadManagerActivity.onCreate(DownloadManagerActivity.java:43)
10-24 17:08:19.711: E/AndroidRuntime(1379): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
10-24 17:08:19.711: E/AndroidRuntime(1379): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1700)
10-24 17:08:19.711: E/AndroidRuntime(1379): ... 11 more

使用 DownloadManager 类,代码如下:

DownloadManager.Request request = new DownloadManager.Request(Uri.parse("http://centraldemangas.com.br/forum/dbtech/vbshop/images/gifts/pidgey.gif"));
request.setAllowedNetworkTypes(Request.NETWORK_MOBILE | Request.NETWORK_WIFI);
request.setAllowedOverRoaming(false);
request.setTitle("pidgey.gif");
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS,"pid.gif");
id = downloadManager.enqueue(request);

异常指向 request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS,"pid.gif");

最佳答案

问题出在

Unable to create directory: /mnt/sdcard/Download

试试这个:

String name = Environment.getExternalStorageDirectory().getAbsolutePath();

name += "/YourDirectoryName/" ;

关于Android:运行时错误 'Unable to create directory',使用类 DownloadManager,方法 setDestinationInExternalPublicDir,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13056109/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com