2
I’m developing an android app, and I need to allow the user to upload a profile photo. The form to create the profile is in a dialog, I have the code that loads the profile photo, but when loading does not return to the dialog, returns to Activity. I would like to upload the photo and put in an imageView that I have in the dialog.
Here is my code:
 ivperfil.setOnClickListener(new View.OnClickListener() {                       
    @Override
    public void onClick(View arg0) {
    // TODO Auto-generated method stub
        Intent i = new Intent(
        Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
        final int ACTIVITY_SELECT_IMAGE = 1234;
        startActivityForResult(i, ACTIVITY_SELECT_IMAGE);
    }
});
And in the way onActivityResult i do:
protected void onActivityResult(int requestCode, int resultCode, Intent data) 
{
    super.onActivityResult(requestCode, resultCode, data); 
    switch(requestCode) { 
    case 1234:
        if(resultCode == RESULT_OK){  
            Uri selectedImage = data.getData();
            String[] filePathColumn = {MediaStore.Images.Media.DATA};
            Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
            cursor.moveToFirst();
            int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            String filePath = cursor.getString(columnIndex);
            cursor.close();
            Bitmap image = BitmapFactory.decodeFile(filePath);
            /* Now you have choosen image in Bitmap format in object "yourSelectedImage". You can use it in way you want! */
            ivperfil.setImageBitmap(image);
            alertD = alertDialogBuilder.create();
            alertD.show();
        }
    }
};
But without ever returning to the dialog, returns to Activity.