在预览界面点了录像,到设置-录像文件夹,点播放闪一下,报错
08-20 13:52:36.370 9445-9445/xxx E/AndroidRuntime: FATAL EXCEPTION: main
Process: xxx, PID: 9445
java.lang.IllegalArgumentException: Failed to find configured root that contains /storage/emulated/0/xxx/2019_08_20_13_34_38-0.mp4
at android.support.v4.content.FileProvider$SimplePathStrategy.getUriForFile(FileProvider.java:712)
at android.support.v4.content.FileProvider.getUriForFile(FileProvider.java:401)
at org.easydarwin.easypusher.MediaFilesActivity$LocalFileFragment.onClick(MediaFilesActivity.java:410)
at android.view.View.performClick(View.java:4457)
at android.view.View$PerformClick.run(View.java:18496)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5291)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
at dalvik.system.NativeStart.main(Native Method)
不知道改了什么,没有提示上面的错误了。
2019-08-20 17:33:53.364 16069-16069/? W/Glide: Load failed for content://org.easydarwin.easyrtmp.fileprovider/RecordFolder/2019_08_20_17_15_55-0.mp4 with size [137x137]
class com.bumptech.glide.load.engine.GlideException: Failed to load resource
There was 1 cause:
java.lang.SecurityException(Permission Denial: opening provider android.support.v4.content.FileProvider from ProcessRecord{be197a5 16069:com.huawei.himovie/u0a145} (pid=16069, uid=10145) that is not exported from UID 10392)
修改前
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
Uri fileUri = FileProvider.getUriForFile(getContext(), getString(R.string.org_easydarwin_update_authorities), mSubFiles[holder.getAdapterPosition()]);
intent.setDataAndType(fileUri, "video/*");
startActivity(intent);
修改后
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
Uri uri = Uri.parse(path);
Log.i(TAG, uri.toString());
intent.setDataAndType(uri, "video/mp4");
startActivity(intent);
Mate9可以播放,但4X不行,点了没反应。
因为有效的地址是这样path=content://media/external/video/media/8292
实际上path=/storage/emulated/0/EasyRTMP/2019_08_20_19_04_38-0.mp4
但神奇的是Mate9可以播放。
解:加授权
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
完整代码
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
File file = new File(path);
Uri fileUri;
fileUri = FileProvider.getUriForFile(getContext(), getString(R.string.org_easydarwin_update_authorities), file);
Log.i(TAG, fileUri.toString());
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
intent.setDataAndType(fileUri, "video/mp4");
参考
Android 7.0 行为变更 通过FileProvider在应用间共享文件吧 - Hongyang - CSDN博客
https://blog.csdn.net/lmj623565791/article/details/72859156
网友评论