if (ContextCompat.checkSelfPermission(mContext, Manifest.permission.READ_EXTERNAL_STORAGE)
== PackageManager.PERMISSION_GRANTED) {
// Permission is granted
return true;
} else {
// Permission is not granted
// Check whether user has denied access and should be shown a rationale
if (ActivityCompat.shouldShowRequestPermissionRationale((Activity) mContext,
Manifest.permission.READ_EXTERNAL_STORAGE)) {
// Show user rationale for needing read external storage permission
} else {
// Request permission
ActivityCompat.requestPermissions((Activity) mContext,
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE);
}
}
// Create a Bitmap object Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.my_image);
// Do something with the Bitmap object
// Release the Bitmap object to free up memory bmp.recycle();
try { // Do something that may cause an exception } catch (Exception e) { // Handle the exception }