2014-09-19 63 views
1

我想從圖庫中挑選圖像,但我希望圖庫僅顯示圖像。我創建了我的意圖就是這樣,但我仍然看到一些設備上圖庫僅挑選圖像

Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); 
    intent.setType("image/*"); 

編輯視頻:

爲我打造這樣的意圖奇巧設備。

 Intent intent = new Intent(Intent.ACTION_GET_CONTENT); 
    intent.setType("image/*"); 
+0

這個鏈接是有關加載位圖從文件到一個GridView – AdrianoCelentano 2014-09-19 11:36:33

回答

0
please try this one  

if (Build.VERSION.SDK_INT < 19) 
{ 
Intent intent = new Intent(); 
intent.setType("image/jpeg"); 
intent.setAction(Intent.ACTION_GET_CONTENT); 
startActivityForResult(DialogsFragment.this, 
Intent.createChooser(intent, "Select Picture"), GALLERY_INTENT_CALLED); 
} 
else 
{ 
Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); startActivityForResult(DialogsFragment.this, intent,GALLERY_KITKAT_INTENT_CALLED); 
} 
+0

這其實是相同的我做,不設置MIME類型 – AdrianoCelentano 2014-09-19 09:56:02

+0

不得不把條件版本明智地 – Jatin 2014-09-19 10:00:08

+0

if(Build.VERSION.SDK_INT <19)\t \t \t \t \t \t Intent intent = new Intent(); \t \t \t \t \t \t intent.setType(「image/jpeg」); \t \t \t \t \t \t intent.setAction(Intent.ACTION_GET_CONTENT); \t \t \t \t \t \t startActivityForResult( \t \t \t \t \t \t \t \t DialogsFragment.this, \t \t \t \t \t \t \t \t Intent.createChooser(意向, 「選擇圖片」), \t \t \t \t \t \t \t \t GALLERY_INTENT_CALLED); \t \t \t \t \t}否則{ \t \t \t \t \t \t \t \t \t \t \t意圖意圖=新意圖( \t \t \t \t \t \t \t \t Intent.ACTION_PICK, \t \t \t \t \t \t \t \t android.provider.MediaStore.Images.Media。EXTERNAL_CONTENT_URI); \t \t \t \t \t \t startActivityForResult( \t \t \t \t \t \t \t \t DialogsFragment.this,意圖, \t \t \t \t \t \t \t \t GALLERY_KITKAT_INTENT_CALLED); \t \t \t \t \t} – Jatin 2014-09-19 10:00:56

0

試試這個:

Intent intent = new Intent(); 
intent.setType("image/*"); 
intent.setAction(Intent.ACTION_GET_CONTENT); 
startActivityForResult(Intent.createChooser(intent, "Select_Picture"), PICK_IMAGE); 
+0

這就像我的代碼 – AdrianoCelentano 2014-09-19 13:26:59

+0

相同,但我提供了兩個選項。你嘗試了第一個選擇嗎? – 2014-09-19 15:31:55

+0

我沒有看到它,你可以編輯你的awnser嗎? – AdrianoCelentano 2014-09-22 11:15:50

0
Add conditions based on OS version 

Try this  

if (Build.VERSION.SDK_INT < 19) { 
       Intent intent = new Intent(); 
       intent.setType("image/jpeg"); 
       intent.setAction(Intent.ACTION_GET_CONTENT); 
       startActivityForResult(DialogsFragment.this, 
         Intent.createChooser(intent, "Select Picture"), 
         GALLERY_INTENT_CALLED); 
      } else { 
       Intent intent = new Intent(
         Intent.ACTION_PICK, 
         android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); 
       startActivityForResult(DialogsFragment.this, intent, 
         GALLERY_KITKAT_INTENT_CALLED); 
      } 
+0

我的代碼有什麼不同? – AdrianoCelentano 2014-09-19 11:47:41

+0

你爲什麼對這個問題有兩個不同的答案@Jatin? – 2Dee 2014-09-23 08:20:53