I have got an app that lets you click on an ImageButton and then brings you to the Android Gallery or the camera. What I am looking for is an onActivityResult method that retrieves the image path from the clicked/ taken image and stores it in a string.
Can someone help me? Here is the onClick method that opens up the Gallery/Camera:
private void showImageDialog() { final String [] items = new String [] {"From Camera", "From SD Card"}; ArrayAdapter<String> adapter = new ArrayAdapter<String> (this, android.R.layout.select_dialog_item,items); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Select Image"); builder.setAdapter( adapter, new DialogInterface.OnClickListener() { public void onClick( DialogInterface dialog, int item ) { if (item == 0) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); File file = new File(Environment.getExternalStorageDirectory(), "tmp_avatar_" + String.valueOf(System.currentTimeMillis()) + ".jpg"); mImageCaptureUri = Uri.fromFile(file); try { intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, mImageCaptureUri); intent.putExtra("return-data", true); startActivityForResult(intent, PICK_FROM_CAMERA); } catch (Exception e) { e.printStackTrace(); } dialog.cancel(); } else { Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); startActivityForResult(Intent.createChooser(intent, "Complete action using"), PICK_FROM_FILE); } } } ); final AlertDialog dialog = builder.create(); dialog.show(); }