【问题标题】:Get Image from gallery cause no activity found error in activity resulte从图库中获取图像,因为在活动结果中未发现活动错误
【发布时间】:2015-06-04 10:36:32
【问题描述】:

我尝试打开图库并让用户从图库中选择图像,它可以在某些 android 上运行,但并非所有在我的平板电脑 (4.2.2) 中都可以正常工作,但我的朋友 (4.1.2) 会导致 ActivityNotFound Exeption。

打开图库的代码:

Intent i = new Intent(
                            Intent.ACTION_PICK,
                            android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                    try
                    {
                        startActivityForResult(i, RESULT_LOAD_IMAGE);
                    }
                    catch (ActivityNotFoundException e) 
                    {
                        e.printStackTrace();
                    }

这是 ActivityResult 代码:

@Override
     public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
            Uri selectedImage = data.getData();
            String[] filePathColumn = { MediaStore.Images.Media.DATA };

            Cursor cursor = getContentResolver().query(selectedImage,
                    filePathColumn, null, null, null);
            cursor.moveToFirst();

            int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            picturePath = cursor.getString(columnIndex);
}

【问题讨论】:

    标签: android android-image android-gallery activitynotfoundexception


    【解决方案1】:

    尝试:-

    Intent intent = new Intent();
    intent.setType("image/*");
    intent.setAction(Intent.ACTION_GET_CONTENT);
    startActivityForResult(Intent.createChooser(intent, "Select Picture"), RESULT_LOAD_IMAGE);
    

    【讨论】:

    • 好的。我对其进行测试并发布结果。
    • 非常感谢。这是完美的作品。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-27
    • 1970-01-01
    相关资源
    最近更新 更多