当文件名不包含阿拉伯语或unicode字符时,我不会得到异常
这是共享文件的代码:
Intent intent = new Intent(Intent.ACTION_SEND);
Uri fileUri = Uri.fromFile(r.getFile());
intent.putExtra(Intent.EXTRA_STREAM, fileUri);
intent.setType("*/*");
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(intent);
例外:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.myapp.appbackup, PID: 2331
android.os.FileUriExposedException: file:///storage/emulated/0/Apk%20Apps/%D8%A7%D8%B0%D9_1.7.0.0.apk exposed beyond app through ClipData.Item.getUri()
at android.os.StrictMode.onFileUriExposed(StrictMode.java:1799)
at android.net.Uri.checkFileUriExposed(Uri.java:2346)
at android.content.ClipData.prepareToLeaveProcess(ClipData.java:832)
at android.content.Intent.prepareToLeaveProcess(Intent.java:8909)
at android.content.Intent.prepareToLeaveProcess(Intent.java:8894)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1517)
at android.app.Activity.startActivityForResult(Activity.java:4224)
at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:50)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:79)
at android.support.v4.app.ActivityCompatJB.startActivityForResult(ActivityCompatJB.java:30)
at android.support.v4.app.ActivityCompat.startActivityForResult(ActivityCompat.java:146)
at android.support.v4.app.FragmentActivity.startActivityFromFragment(FragmentActivity.java:932)
at android.support.v4.app.FragmentActivity$HostCallbacks.onStartActivityFromFragment(FragmentActivity.java:1047)
at android.support.v4.app.Fragment.startActivity(Fragment.java:935)
at android.support.v4.app.Fragment.startActivity(Fragment.java:924)
at com.myapp.appbackup.fragment.RestoreFragment$3.onItemClick(RestoreFragment.java:174)
at android.widget.AdapterView.performItemClick(AdapterView.java:310)
at android.widget.AbsListView.performItemClick(AbsListView.java:1155)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:3126)
at android.widget.AbsListView$3.run(AbsListView.java:4041)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
可以解决这个问题的方法是什么?
答案 0 :(得分:0)
我强烈建议不要在文件名和目录名中使用unicode字符,以确保您的应用程序可以处理不同的Android版本和各种设备品牌。
我使用了pdf
和doc
提交了unicode和arabic内容,但我没有使用阿拉伯字符作为文件名。你可能也不需要它,可以找到一种解决方法来避免它。