In my mainactivity
class, on clicking a button, it displays a dialog that shows, "capture a photo", "capture a video", pick from gallery" buttons upon clicking any of those button it has to do the respective action and return the path of file to mainactivity
.
It is easy to do with startActivityForResult&onActivityResult
within mainactivity
.
But how can I use intent with in custom dialog and return the intent result from custom dialog to mainactivity
.
Thanks for your time.
takeaPhoto.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, ACTION_TAKE_PHOTO);
}
});
public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch(){
//do action
String filePath = data.getDataString();
filename.setText(filePath);
}
}
It's not tough. Just use alert Dialog and make sure that your views are right.
final Context context = this;
static final int SELECT_PICTURE = 1;
takeaphoto.setOnClickListener(new View.OnClickListener() {
public void onClick(View v){
LayoutInflater myLayout = LayoutInflater.from(context);
final View dialogView = myLayout.inflate(R.layout.YOURCUSTOM.XML, null);
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
alertDialogBuilder.setView(dialogView);
final AlertDialog alertDialog = alertDialogBuilder.create();
Button button1 = (Button) dialogView.findViewById(R.id.button1);
button1.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(intent, SELECT_PICTURE);
}});
alertDialog.show();
return;}});