@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
 @Override
 public void onRequestPermissionsResult(
     int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
   if (requestCode == MY_PERMISSIONS_REQUEST) {
     Map<String, Integer> perms = new HashMap<>();
     // Initial
     perms.put(Manifest.permission.READ_EXTERNAL_STORAGE, PackageManager.PERMISSION_GRANTED);
     perms.put(Manifest.permission.WRITE_EXTERNAL_STORAGE, PackageManager.PERMISSION_GRANTED);
     perms.put(Manifest.permission.RECORD_AUDIO, PackageManager.PERMISSION_GRANTED);
     // Fill with results
     for (int i = 0; i < permissions.length; i++) {
       perms.put(permissions[i], grantResults[i]);
     }
     if (perms.get(Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED
         && perms.get(Manifest.permission.WRITE_EXTERNAL_STORAGE)
             == PackageManager.PERMISSION_GRANTED
         && perms.get(Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED) {
       CommonUtils.getInstance().showMessage("All permissions granted.");
       onPermissionsGranted();
     } else {
       CommonUtils.getInstance().showMessage("Some permissions not granted.");
       onPermissionsDenied();
     }
   }
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    localStorage = LocalStorage.getInstance();
    helperUtils = CommonUtils.getInstance();
  }
 /** Convenience method to ask user to grant permissions. */
 @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
 protected void requestPermissions() {
   boolean shouldShowRationale =
       ActivityCompat.shouldShowRequestPermissionRationale(
               this, Manifest.permission.READ_EXTERNAL_STORAGE)
           || ActivityCompat.shouldShowRequestPermissionRationale(
               this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
           || ActivityCompat.shouldShowRequestPermissionRationale(
               this, Manifest.permission.RECORD_AUDIO);
   if (shouldShowRationale) {
     CommonUtils.getInstance().showMessage(R.string.Grant_necessary_permissions);
   } else {
     ActivityCompat.requestPermissions(
         this,
         new String[] {
           Manifest.permission.READ_EXTERNAL_STORAGE,
           Manifest.permission.WRITE_EXTERNAL_STORAGE,
           Manifest.permission.RECORD_AUDIO
         },
         MY_PERMISSIONS_REQUEST);
   }
 }