2012-11-20 38 views
1

我要挑從畫廊的照片,但是從下面的代碼顯示與SD卡外部應用程序,如前天文經理畫廊。我想它應該告訴我只有畫廊沒有其他第三方應用程序或相關的東西等如何從圖庫中選擇圖像僅

虛設碼目前列出所有可以瀏覽像天文經理等

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

回答

3

你的代碼的應用程序是正確的,但你需要我的幫助。只是看起來在鏈接它會幫助你處理庫Link

對於你的任務,你可以添加此示例代碼

Intent i = new Intent(
Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); 
startActivityForResult(i, RESULT_LOAD_IMAGE); 
+1

鏈接唯一的答案是不是好主意,就那麼現在這就是爲什麼我有一些代碼編輯你的答案。 –

+0

它顯示畫廊和照片 – Prasad

0

試試這個 -

private static final int PICTURE_GALLERY = 1; 
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); 
startActivityForResult(photoPickerIntent, PICTURE_GALLERY); 
0

如果您的應用支持SDK版本JELLY_BEAN_MR2。這是更好地打開意圖一樣,

Intent intent; 
    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN_MR2) { 
     intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI); 
     intent.setType("image/*"); 
    } else { 
     intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); 
     intent.addCategory(Intent.CATEGORY_OPENABLE); 
     intent.setType("image/*"); 
    } 
checkAndStartActivityForResult(intent, RESULT_LOAD_IMAGE); 


private void checkAndStartActivityForResult(Intent intent, int requestCode) { 
    //Open only if any intent can be handled from some component 
    if (intent.resolveActivity(getActivity().getPackageManager())!=null) { 
     startActivityForResult(createChooser(intent, ""), requestCode); 
    }else{ 
    //show error to user 
    } 
}