Android 从SD卡中拾取设备摄像头未拍摄的照片

Android 从SD卡中拾取设备摄像头未拍摄的照片,android,Android,我试图使用以下意图从sd卡中挑选照片: Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); startActivityForResult(Intent.createChooser(intent, this.getResources().getString(R.string.title_pick_photo)), Globals.REQUEST_C

我试图使用以下意图从sd卡中挑选照片:

Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, this.getResources().getString(R.string.title_pick_photo)), Globals.REQUEST_CODE_PICK_PHOTO);

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if(requestCode == Globals.REQUEST_CODE_PICK_PHOTO) {
        if(resultCode == RESULT_OK) {
            this.onPhotoPicked(Helper.getAbsoluteImagePath(this, data.getData()));
        }
    }
}

private void onPhotoPicked(String imagePath) {
    this.imagePicked = true;
    this.imageTaken = false;
    this.imagePath = imagePath;

    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inSampleSize = 4;

    Bitmap bitmap = BitmapFactory.decodeFile(this.imagePath, options);
    this.imageViewPhoto.setImageBitmap(bitmap);
}
这适用于我选择的由设备摄像头拍摄的所有照片。 如果我想选择其他地方的照片,请使用此方法:

public static String getAbsoluteImagePath(Context context, Uri uri) {
    String[] projection = { MediaStore.Images.Media.DATA };
    Cursor cursor = context.getContentResolver().query(uri, projection, null, null, null);

    if (cursor != null) {
        int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        cursor.moveToFirst();

        return cursor.getString(columnIndex);
    } else {
        return null;
    }
}
但不知何故,这不适用于我从sd卡中挑选的照片,而sd卡在哪里 不像下载、dropbox或facebook照片那样由设备摄像头拍摄。 如果我尝试游标,则getStringcolumnIndex始终为空


那么,我如何才能选择那些不是由相机拍摄的照片呢?

您是否已将此权限添加到清单中

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

Gallery的pic photo中存在问题。在这种方法中,您没有传递任何字符串This.onphototake;不,因为我不需要。这张照片拍得很好。onPhotoPicked是问题所在。请使用此代码。当我们从Gallery拍摄照片时不需要此权限是的,我已添加这些权限。