0

I have written the following code to store the taken image photo. But for some reason, it works in all Android OS in United States but it does not work in Nougat Bulgaria. I do not have access to Bulgaria, but my app user saying that they cannot able to store the image.

Post.java

@Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        switch (requestCode) {
            case PermissionUtil.MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE:
                if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                    switch (ImageUtil.userSelectionID) {
                        case R.id.selectPhotoProduct:
                            ImageUtil.showFileChooser(this);
                            break;
                        case R.id.takePhotoProduct:
                            if(PermissionUtil.checkPhotoPermission(this) ) {
                                ImageUtil.buildPicturePickerIntent(this.getPackageManager(), this);
                            }
                            break;
                        default:
                            break;
                    }
                }
                else {
                    // Deny code!! A message can be given.
                }
                break;
            case PermissionUtil.MY_PERMISSIONS_REQUEST_CAMERA:
                if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                    switch (ImageUtil.userSelectionID) {
                        case R.id.selectPhotoProduct:
                            if(PermissionUtil.checkStoragePermission(this)) {
                                ImageUtil.showFileChooser(this);
                            }
                            break;
                        case R.id.takePhotoProduct:
                            if(PermissionUtil.checkStoragePermission(this)) {
                                ImageUtil.buildPicturePickerIntent(this.getPackageManager(), this);
                            }
                            break;
                        default:
                            break;
                    }
                }
                else {
                    // Deny code!! A message can be given.
                }
                break;
            default:
                break;
        }
    }

PermissionUtil.java

 @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
 public static boolean checkStoragePermission(final Context context)
 {
        int currentAPIVersion = Build.VERSION.SDK_INT;
        if(currentAPIVersion>=android.os.Build.VERSION_CODES.M)
        {
            if (ContextCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
                if (ActivityCompat.shouldShowRequestPermissionRationale((Activity) context, android.Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
                    AlertDialog.Builder alertBuilder = new AlertDialog.Builder(context);
                    alertBuilder.setCancelable(true);
                    alertBuilder.setTitle(context.getString(R.string.permission_necessary));
                    alertBuilder.setMessage(context.getString(R.string.camera_permission_necessary));
                    alertBuilder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                        @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
                        public void onClick(DialogInterface dialog, int which) {
                            ActivityCompat.requestPermissions((Activity) context, new String[]{android.Manifest.permission.WRITE_EXTERNAL_STORAGE}, MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE);
                        }
                    });
                    AlertDialog alert = alertBuilder.create();
                    alert.show();
                } else {
                    ActivityCompat.requestPermissions((Activity) context, new String[]{android.Manifest.permission.WRITE_EXTERNAL_STORAGE}, MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE);
                }
                return false;
            } else {
                return true;
            }
        } else {
            return true;
        }
}
casillas
  • 16,351
  • 19
  • 115
  • 215
  • Please explain, **in detail**, what "it does not work" means. – CommonsWare Nov 24 '16 at 14:42
  • @CommonsWare I have added little bit more explanation – casillas Nov 24 '16 at 14:53
  • You will need to ask your user to explain in greater detail what "they cannot able to store the image" means. Also, you have no code that stores images in your question. – CommonsWare Nov 24 '16 at 14:54
  • @CommonsWare I have added the rest of the code. I am having this issue only in the Nougat. Do you see any part which I am missing for Nougat. it works on Kitkat, Lollilop, Marshmallow, but not for Nougat. – casillas Nov 24 '16 at 14:56
  • "I have added the rest of the code" -- you have no code that stores images in your question. "Do you see any part which I am missing for Nougat" -- you are missing the code that stores images, which is what the user says is not working. – CommonsWare Nov 24 '16 at 14:58

0 Answers0