Reputation: 180
My activity gets the Uri of a shared video and saves it to the database:
@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
// ...
}
}
If the video is shared with Android's File Explorer Log.i prints
content://media/external/video/media/8719
whereas if the video is shared with MxPlayer the Log.i prints
content://com.mxtech.videoplayer.pro.fileprovider/external_storage_root/Movies/20201026_192614.mp4
After restarting the App it's only possible to play the video with the first Uri. Using the latter Uri leads to
Caused by: java.io.FileNotFoundException: No content provider: content://com.mxtech.videoplayer.pro.fileprovider/external_storage_root/Movies/20201026_192614.mp4
How do I handle Uris from thirdparty Apps? Is it possible to convert the shared Uri to a "generic" format? Is it a permission issue?
Upvotes: 1
Views: 264
Reputation: 1007321
When you get a Uri
, you have very limited time to use it. And for a Uri
that you get from ACTION_SEND
, you should assume that:
ACTION_SEND
Intent
can use the Uri
Uri
and use it in the futureHow do I handle Uris from thirdparty Apps?
For ACTION_SEND
, use it immediately. Do not attempt to save it to a database. For a Uri
that you get via ACTION_OPEN_DOCUMENT
, you have more options.
Is it possible to convert the shared Uri to a "generic" format?
No, sorry.
Upvotes: 1