Snippets

cutiko AlertDialog with Camera and Gallery Intent onActivityforResults

Created by cutiko
findSomeElement.setOnClickListener(new View.OnClickListener() {
  @Override
  public void onClick(View v) {
    /*this can also be getApplicationContext(), the important is to get the context*/
    new AlertDialog.Builder(this())
    /*Instead */
      .setTitle("Title")
      .setMessage("Mensaje")
      .setPositiveButton("Camera", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            /*Calling the camera*/
          Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
          startActivityForResult(intent, 0);
          dialog.cancel();
        }
      }).setNegativeButton("Gallery", new DialogInterface.OnClickListener() {
      public void onClick(DialogInterface dialog, int which) {
      /*Select Image from Gallery*/
        Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
        intent.setType("image/*");
        startActivityForResult(intent, 0);
        dialog.cancel();
      }
    }).setIcon(android.R.drawable.ic_dialog_alert)
      .show();
  }
});

Comments (0)