2014-11-05 44 views
1

我想摘使用这种意图从我的SD卡上的照片:从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); 
} 

也能正常工作的所有照片我选择哪个那里采取设备相机。 如果我想选择从其他地方THX照片,这个方法:

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卡接工作Facebook照片。 如果我尝试cursor.getString(columnIndex)始终为空。

那么我该如何挑选哪些不在相机拍摄的照片呢?

+0

问题在图片库中的照片 – 2014-11-05 11:02:50

+0

有没有通过任何字符串在这方法this.onPhotoTaken(); – 2014-11-05 11:05:34

+0

不,因为我不需要。 onPhotoTaken工作正常。 onPhotoPicked()是问题。 – Mulgard 2014-11-05 11:06:00

回答

0

您是否在清单中添加了此权限?

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

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

当我们从相册中拍摄照片时,不需要此权限 – 2014-11-05 11:04:40

+0

是的,我已经添加了这些权限。 – Mulgard 2014-11-05 11:04:56