问题
I'm trying to invoke android gallery with videos loaded with it. This method working fine for the intent android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI
but it doesn't work properly for me and returned following exceptions. Can someone hlep me out please.
08-09 17:12:26.992: ERROR/AndroidRuntime(878): java.lang.RuntimeException: Unable to start activity ComponentInfo{a.b/a.b.SDCardVideoActivity}: java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.PICK dat=content://media/external/video/media cmp=com.google.android.music/com.android.music.VideoBrowserActivity } from ProcessRecord{4052da08 878:a.b/10053} (pid=878, uid=10053) requires null
08-09 17:12:26.992: ERROR/AndroidRuntime(878): Caused by: java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.PICK dat=content://media/external/video/media cmp=com.google.android.music/com.android.music.VideoBrowserActivity } from ProcessRecord{4052da08 878:a.b/10053} (pid=878, uid=10053) requires null
My code goes as below
public class SDCardVideoActivity extends Activity {
final int REQ_CODE_PICK_VIDEO = 1;
String outputfilepath;
SQLiteDatabase db;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.header);
Intent i = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, REQ_CODE_PICK_VIDEO);
}
}
回答1:
I have used the below code to invoke Gallery Application from my activity.
// contentId will have the video content id as given by Content Resolver
// In this nparticular application, contentId is retrieved from ListActivity with custom adapter
Uri contentUri = ContentUris.withAppendedId(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, contentId);
try {
Intent intent = new Intent(Intent.ACTION_VIEW, contentUri);
startActivity(intent);
}
catch (ActivityNotFoundException e) {
Toast.makeText(this, "Not Supported", Toast.LENGTH_SHORT).show();
}
EDIT 1
To invoke Gallery browser use the below code
someMethod() {
Intent intent = new Intent(Intent.ACTION_PICK, null);
intent.setType("video/*");
startActivityForResult(intent, 1);
}
To invoke Video Player use the below code
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if ((requestCode == 1) && (resultCode == RESULT_OK) && (data != null)) {
Log.i("---------------------", data.getData().getEncodedPath());
mIntentFromGallery = data;
Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.setType("video/*");
intent.setData(data.getData());
try
{
startActivity(intent);
}
catch(Exception e)
{
}
} else {
setResult(RESULT_CANCELED);
finish();
}
}
Shash
来源:https://stackoverflow.com/questions/6995901/android-unable-to-invoke-gallery-with-video