2014-11-05 40 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