In my app when user press on an 'ImageView' i am creating a chooser intent that will promote the user to change the picture.
Here is the code i use when user click on the ImageView
userProfileIMG.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
photoPickerIntent.setType("image/*");
Intent takePhotoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePhotoIntent.resolveActivity(getPackageManager()) != null)
{
try
{
photoFile = Create_ImageFile();
}
catch (Exception e)
{
Log.e("file", e.toString());
}
if (photoFile != null)
{
takePhotoIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile.getAbsoluteFile()));
}
}
String pickTitle = getString(R.string.select_or_take_new_picture);
Intent chooserIntent = Intent.createChooser(photoPickerIntent, pickTitle);
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[]{takePhotoIntent});
startActivityForResult(chooserIntent, ACTIVITY_SELECT_PICTURE);
}
});
And this is the result
My problem is when user press on 'Gallery' and select an image on 6.0 its giving security exception because i want to request the <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
only if he pressed 'Gallery' is there is any way to override the behavior when user press 'Gallery' so that i request the permission then if he granted i let him to continue to the gallery else i deny him?
Or i have to build the same chooser manually not depending on the system to build the dialog for me?