android.os.FileUriExposedException: file:///storage/emulated/0/DCIM/Camera/TRIM_20210816_093720.mp4
--------- beginning of crash08-16 09:37:22.34646024602 E AndroidRuntime: FATAL EXCEPTION: main08-16 09:37:22.34646024602 E AndroidRuntime: Process: com.android.gallery3d, PID: 460208-16 09:37:22.34646
·
--------- beginning of crash
08-16 09:37:22.346 4602 4602 E AndroidRuntime: FATAL EXCEPTION: main
08-16 09:37:22.346 4602 4602 E AndroidRuntime: Process: com.android.gallery3d, PID: 4602
08-16 09:37:22.346 4602 4602 E AndroidRuntime: android.os.FileUriExposedException: file:///storage/emulated/0/DCIM/Camera/TRIM_20210816_093720.mp4 exposed beyond app through Intent.getData()
08-16 09:37:22.346 4602 4602 E AndroidRuntime: at android.os.StrictMode.onFileUriExposed(StrictMode.java:2141)
08-16 09:37:22.346 4602 4602 E AndroidRuntime: at android.net.Uri.checkFileUriExposed(Uri.java:2391)
08-16 09:37:22.346 4602 4602 E AndroidRuntime: at android.content.Intent.prepareToLeaveProcess(Intent.java:11165)
08-16 09:37:22.346 4602 4602 E AndroidRuntime: at android.content.Intent.prepareToLeaveProcess(Intent.java:11116)
08-16 09:37:22.346 4602 4602 E AndroidRuntime: at android.app.Instrumentation.execStartActivity(Instrumentation.java:1724)
08-16 09:37:22.346 4602 4602 E AndroidRuntime: at android.app.Activity.startActivityForResult(Activity.java:5320)
08-16 09:37:22.346 4602 4602 E AndroidRuntime: at android.app.Activity.startActivityForResult(Activity.java:5278)
08-16 09:37:22.346 4602 4602 E AndroidRuntime: at android.app.Activity.startActivity(Activity.java:5664)
08-16 09:37:22.346 4602 4602 E AndroidRuntime: at android.app.Activity.startActivity(Activity.java:5617)
08-16 09:37:22.346 4602 4602 E AndroidRuntime: at com.android.gallery3d.app.TrimVideo$4$1.run(TrimVideo.java:304)
08-16 09:37:22.346 4602 4602 E AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:938)
08-16 09:37:22.346 4602 4602 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:99)
08-16 09:37:22.346 4602 4602 E AndroidRuntime: at android.os.Looper.loop(Looper.java:223)
08-16 09:37:22.346 4602 4602 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:7697)
08-16 09:37:22.346 4602 4602 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
报错的代码如下:
// Show the result only when the activity not stopped.
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(mDstFileInfo.mFile), "video/*");
intent.putExtra(MediaStore.EXTRA_FINISH_ON_COMPLETION, false);
startActivity(intent);
finish();
修改:
diff --git a/packages/apps/Gallery2/src/com/android/gallery3d/app/TrimVideo.java b/packages/apps/Gallery2/src/com/android/gallery3d/app/TrimVideo.java
index bc4efe0..489182c 100755
--- a/packages/apps/Gallery2/src/com/android/gallery3d/app/TrimVideo.java
+++ b/packages/apps/Gallery2/src/com/android/gallery3d/app/TrimVideo.java
@@ -36,7 +36,9 @@ import android.widget.VideoView;
import com.android.gallery3d.R;
import com.android.gallery3d.util.SaveVideoFileInfo;
import com.android.gallery3d.util.SaveVideoFileUtils;
-
+//<!--jicong.wang modify for bug 26051
+import androidx.core.content.FileProvider;
+//jicong.wang modify for bug 26051 -->
import java.io.File;
import java.io.IOException;
@@ -299,7 +301,12 @@ public class TrimVideo extends Activity implements
mProgress = null;
// Show the result only when the activity not stopped.
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
- intent.setDataAndType(Uri.fromFile(mDstFileInfo.mFile), "video/*");
+ //<!--jicong.wang modify for bug 26051
+ //intent.setDataAndType(Uri.fromFile(mDstFileInfo.mFile), "video/*");
+ intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
+ Uri uri = FileProvider.getUriForFile(getApplicationContext(), getApplicationContext().getPackageName() + ".files", mDstFileInfo.mFile);
+ intent.setDataAndType(uri, "video/*");
+ //jicong.wang modify for bug 26051 -->
intent.putExtra(MediaStore.EXTRA_FINISH_ON_COMPLETION, false);
startActivity(intent);
finish();
更多推荐
所有评论(0)