Android intent to open video with raw resource?

2019-01-28 11:42发布

问题:

Does anyone know of an intent I can use to open a raw mp4 resource in the phone's video player? I tried this code:

    Uri video = Uri.parse( "android.resource://" + getPackageName() + "/" + R.raw.video );
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(video, "video/*");
    startActivity(intent);

This threw an ActivityNotFoundException, however this has worked for me when the URI was the sdcard and the video was located there. Does anyone know how I can use the above code with a resource file in my app?

回答1:

Other apps can't access your resources. You'll need to create a ContentProvider, or store the data in a place accessible to anyone (either SD card, or in a public folder in your local storage).