Android:无法使用视频调用图库

发布于 2024-11-28 12:50:31 字数 1493 浏览 1 评论 0原文

我正在尝试调用 android gallery 并加载其中的视频。此方法对于意图 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

我的代码如下

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

}

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

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陪我终i 2024-12-05 12:50:31

我已使用以下代码从我的活动中调用图库应用程序。

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

Shash

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文