gpt4 book ai didi

Android:无法调用带有视频的图库

转载 作者:行者123 更新时间:2023-11-29 14:25:35 25 4
gpt4 key购买 nike

我正在尝试调用加载了视频的 android 画廊。此方法可以很好地满足 android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI 的 Intent ,但它对我来说无法正常工作并返回以下异常。有人可以帮助我吗?

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

我的代码如下

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);
}

}

最佳答案

我已使用以下代码从我的 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();
}

编辑 1

调用图库浏览器使用下面的代码

someMethod() {
Intent intent = new Intent(Intent.ACTION_PICK, null);
intent.setType("video/*");
startActivityForResult(intent, 1);
}

调用视频播放器使用下面的代码

@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();
}
}

哈希

关于Android:无法调用带有视频的图库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6995901/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com