gpt4 book ai didi

android - java.lang.SecurityException : Destination must be on external storage 错误

转载 作者:行者123 更新时间:2023-11-29 14:51:38 24 4
gpt4 key购买 nike

在android TV中,U盘挂载/mnt/usb/sdb4,使用android DownloadManage,

 File pathyr = new File("/mnt/usb/sdb4");
Uri downloadUri = Uri.parse(DOWNLOAD_FILE);
DownloadManager.Request request = new DownloadManager.Request(downloadUri);
request.setDestinationUri(Uri.fromFile(new File( pathyr,"100mb.jpg") ));

04-20 10:54:05.593: W/dalvikvm(2315): threadid=1: thread exiting with uncaught exception (group=0x40f771f8)
04-20 10:54:05.665: E/AndroidRuntime(2315): FATAL EXCEPTION: main
04-20 10:54:05.665: E/AndroidRuntime(2315): java.lang.SecurityException: Destination must be on external storage: file:///mnt/usb/sdb4/100mb.test.test
04-20 10:54:05.665: E/AndroidRuntime(2315): at android.os.Parcel.readException(Parcel.java:1327)
04-20 10:54:05.665: E/AndroidRuntime(2315): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:181)
04-20 10:54:05.665: E/AndroidRuntime(2315): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
04-20 10:54:05.665: E/AndroidRuntime(2315): at android.content.ContentProviderProxy.insert(ContentProviderNative.java:415)
04-20 10:54:05.665: E/AndroidRuntime(2315): at android.content.ContentResolver.insert(ContentResolver.java:730)
04-20 10:54:05.665: E/AndroidRuntime(2315): at com.exercise.download.DownloadManager.enqueue(DownloadManager.java:750)
04-20 10:54:05.665: E/AndroidRuntime(2315): at com.exercise.AndroidDownloadManager.AndroidDownloadManagerActivity$1.onClick(AndroidDownloadManagerActivity.java:71)
04-20 10:54:05.665: E/AndroidRuntime(2315): at android.view.View.performClick(View.java:3511)
04-20 10:54:05.665: E/AndroidRuntime(2315): at android.view.View.onKeyUp(View.java:6073)
04-20 10:54:05.665: E/AndroidRuntime(2315): at android.widget.TextView.onKeyUp(TextView.java:5595)
04-20 10:54:05.665: E/AndroidRuntime(2315): at android.view.KeyEvent.dispatch(KeyEvent.java:3010)
04-20 10:54:05.665: E/AndroidRuntime(2315): at android.view.View.dispatchKeyEvent(View.java:5500)
04-20 10:54:05.665: E/AndroidRuntime(2315): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1246)
04-20 10:54:05.665: E/AndroidRuntime(2315): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1246)
04-20 10:54:05.665: E/AndroidRuntime(2315): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1246)
04-20 10:54:05.665: E/AndroidRuntime(2315): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1246)
04-20 10:54:05.665: E/AndroidRuntime(2315): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:1879)
04-20 10:54:05.665: E/AndroidRuntime(2315): at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1361)
04-20 10:54:05.665: E/AndroidRuntime(2315): at android.app.Activity.dispatchKeyEvent(Activity.java:2325)
04-20 10:54:05.665: E/AndroidRuntime(2315): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1806)
04-20 10:54:05.665: E/AndroidRuntime(2315): at android.view.ViewRootImpl.deliverKeyEventPostIme(ViewRootImpl.java:3327)
04-20 10:54:05.665: E/AndroidRuntime(2315): at android.view.ViewRootImpl.handleFinishedEvent(ViewRootImpl.java:3300)
04-20 10:54:05.665: E/AndroidRuntime(2315): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2460)
04-20 10:54:05.665: E/AndroidRuntime(2315): at android.os.Handler.dispatchMessage(Handler.java:99)
04-20 10:54:05.665: E/AndroidRuntime(2315): at android.os.Looper.loop(Looper.java:137)
04-20 10:54:05.665: E/AndroidRuntime(2315): at android.app.ActivityThread.main(ActivityThread.java:4424)
04-20 10:54:05.665: E/AndroidRuntime(2315): at java.lang.reflect.Method.invokeNative(Native Method)
04-20 10:54:05.665: E/AndroidRuntime(2315): at java.lang.reflect.Method.invoke(Method.java:511)
04-20 10:54:05.665: E/AndroidRuntime(2315): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:853)
04-20 10:54:05.665: E/AndroidRuntime(2315): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:579)
04-20 10:54:05.665: E/AndroidRuntime(2315): at dalvik.system.NativeStart.main(Native Method)

最佳答案

目前,DownloadManager 请求仅接受“标准”外部存储上的路径,由 Environment.getExternalStoragePublicDirectory(yourDirOfChoice)Environment 检索。 getExternalStorageDirectory();否则,它会抛出这个异常。

有关详细信息,请参阅 this StackOverflow 问题。

关于android - java.lang.SecurityException : Destination must be on external storage 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16116224/

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