2017-08-27 122 views
0

當我從圖庫中獲取圖像時,SELECT_PICTURE上出現錯誤。 人幫助me.The代碼:從圖庫中獲取圖片

Intent intent = new Intent(); intent.setType("image/*"); 
intent.setAction(Intent.ACTION_GET_CONTENT); 
startActivityForResult(Intent.createChooser(intent,"Select Picture"),SELECT_PICTURE); 
+1

請發佈錯誤日誌 –

+0

錯誤是什麼? SELECT_PICTURE是一個請求代碼,你給它有什麼價值嗎?究竟是什麼錯誤? – Sahil

回答

0

在按鈕的Click事件,調用此函數

private void showImageChooser(){ 
     Intent pickIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); 
     pickIntent.setType("image/*"); 
     Intent chooserIntent = Intent.createChooser(pickIntent, "Select Image"); 
     startActivityForResult(chooserIntent, 500); 
    } 

在OnActivityResult

@Override 
public void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 
    if(requestCode == 500 && resultCode == RESULT_OK && data != null){ 
     imageFile = data.getData(); 
     Glide.with(getApplicationContext()).load(imageFile).into(profilePic); 
    } 
} 

請使用您的ImageView到位profilePic的。