Jay*_*ayu 1 video android gallery android-intent
我正在尝试用加载它的视频调用android库.此方法适用于意图,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI但它不能正常工作,并返回以下异常.有人可以把我赶出去吗
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
Run Code Online (Sandbox Code Playgroud)
我的代码如下
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);
}
}
Run Code Online (Sandbox Code Playgroud)
Sha*_*316 10
我使用以下代码从我的活动中调用Gallery Application.
// 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();
}
Run Code Online (Sandbox Code Playgroud)
编辑1
要调用Gallery浏览器,请使用以下代码
someMethod() {
Intent intent = new Intent(Intent.ACTION_PICK, null);
intent.setType("video/*");
startActivityForResult(intent, 1);
}
Run Code Online (Sandbox Code Playgroud)
要调用视频播放器,请使用以下代码
@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();
}
}
Run Code Online (Sandbox Code Playgroud)
词shash
| 归档时间: |
|
| 查看次数: |
4392 次 |
| 最近记录: |