2013-03-23 15 views
0

下面的代碼啓動畫廊可供選擇的圖像:怎麼知道的意圖ACTION_PICK想出什麼

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

現在,我的問題是,我怎麼能知道的是,意圖藉助回來onResultActivity()方法沒有選擇? (即用戶沒有從畫廊中選擇任何圖像,只需點擊取消按鈕)

我正在使用下面的代碼,但它並沒有幫助我完成任務!

Uri imageUriForGallery = intent.getData(); 
if(imageUriForGallery == null || imageUriForGallery.toString() == null) { 
    Toast.makeText(this, "You didn't choose an image", Toast.LENGTH_LONG).show(); 
     break; 
} 

當用戶不選擇從庫中的圖像和簡單地打在畫廊的取消按鈕,我的應用程序崩潰!

回答

1

現在,我的問題是我怎樣才能知道在onResultActivity()方法意圖回來沒有選擇?

您的onActivityResult() method將在第二個參數中被稱爲with RESULT_CANCELED

+0

非常感謝!如果你也解決了這個問題,這將是很高興的 (http://stackoverflow.com/questions/15589299/camera-is-not-returing-back-me-captured-image) – 2013-03-23 19:15:06

相關問題