共享视频 Uri 在应用重启后导致 "No content provider"

Shared Video Uri leads to "No content provider" after App restart

我的activity获取共享视频的Uri并将其保存到数据库:

@Override
protected void onCreate(Bundle savedInstanceState) {
    Intent intent = getIntent();
    String action = intent.getAction();
    String type = intent.getType();

    if (Intent.ACTION_SEND.equals(action) && type.startsWith("video")){
        Uri uri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
        Log.i("MyActivity", uri.toString());
        // save uri.toString() to database
        // ...
    }
}

如果视频与 Android 的文件资源管理器共享 Log.i 打印

content://media/external/video/media/8719

而如果视频与 MxPlayer 共享,则 Log.i 打印

content://com.mxtech.videoplayer.pro.fileprovider/external_storage_root/Movies/20201026_192614.mp4

重启后只能播放第一个Uri的视频。使用后一个 Uri 导致

Caused by: java.io.FileNotFoundException: No content provider: content://com.mxtech.videoplayer.pro.fileprovider/external_storage_root/Movies/20201026_192614.mp4

如何处理来自第三方应用程序的 Uris?是否可以将共享 Uri 转换为“通用”格式?是权限问题吗?

当您获得 Uri 时,您使用它的时间非常有限。对于从 ACTION_SEND 获得的 Uri,您应该假设:

  • 您的 activity 响应 ACTION_SEND Intent 可以使用 Uri
  • 您不能保留 Uri 并在将来使用它

How do I handle Uris from thirdparty Apps?

对于ACTION_SEND,立即使用。不要试图将其保存到数据库中。对于通过 ACTION_OPEN_DOCUMENTyou have more options.

获得的 Uri

Is it possible to convert the shared Uri to a "generic" format?

不,抱歉。