2012-06-09 65 views
-1

我正在爲我的應用程序編寫代碼,並且我陷入了試圖弄清楚這一點。呼叫畫廊帶回圖像

我想通過應用程序,然後調用從GALLERY如果用戶選擇的圖像,該圖像是帶回我的應用程序的進一步行動,而不是畫廊開幕它

PLZ幫我編寫此,在此先感謝:)

+1

請看右側的相關問題。有很多問題可以解答你的問題。 – ariefbayu

回答

1
startActivityForResult(new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI), SELECT_IMAGE); 

要在SD Card.Uri獲取圖像將

android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI

onActivityResult方法:

protected void onActivityResult(int requestCode, int resultCode, 
     Intent intent) { 
    super.onActivityResult(requestCode, resultCode, intent); 

    if (resultCode == RESULT_OK) { 
     Uri photoUri = intent.getData(); 

     if (photoUri != null) { 
      try { 
       Bitmap bitmap = MediaStore.Images.Media.getBitmap(this 
        .getContentResolver(), photoUri); 

       //Now you can upload this bitmap to server or do something else. 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 
     } 
    } 
} 
0

檢查這裏的答案:Pick an image from the Gallery

Intent intent = new Intent(Intent.ACTION_PICK); 
intent.setType("image/*"); 
//intent.setAction(Intent.ACTION_GET_CONTENT); 
startActivityForResult(intent, 1);