2017-08-27 2 views
0

Wenn ich ein Bild aus der Galerie hole, bekomme ich einen Fehler bei SELECT_PICTURE. Jeder me.The Code helfen ist:Ein Bild aus der Galerie holen

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

Bitte Fehler melden –

+0

was ist der Fehler? SELECT_PICTURE ist ein Anforderungscode, haben Sie ihm einen Wert gegeben? Was genau ist der Fehler? – Sahil

Antwort

0

On Button Click-Ereignis, rufen Sie diese Funktion

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); 
    } 

In 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); 
    } 
} 

Sie bitte Ihre Image anstelle von profilePic verwenden.

Verwandte Themen