private void requestPermissionIfNeeded(){
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
    int hasEnableCoarseLocationPerm=checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION);
    int hasEnableFineLocationPerm=checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION);
    int hasEnableExternalWritePerm=checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE);
    List<String> permissionToRequest=new ArrayList<>();
    if (hasEnableCoarseLocationPerm == PackageManager.PERMISSION_DENIED) {
      permissionToRequest.add(Manifest.permission.ACCESS_COARSE_LOCATION);
    }
    if (hasEnableFineLocationPerm == PackageManager.PERMISSION_DENIED) {
      permissionToRequest.add(Manifest.permission.ACCESS_FINE_LOCATION);
    }
    if (hasEnableExternalWritePerm == PackageManager.PERMISSION_DENIED) {
      permissionToRequest.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
    }
    if (!permissionToRequest.isEmpty()) {
      requestPermissions(permissionToRequest.toArray(new String[permissionToRequest.size()]),ALLOW_PERMISSIONS);
    }
 else {
      initEvent();
    }
  }
}

private void requestPermissionIfNeeded ( ) { if ( Build . VERSION . SDK_INT >= Build . VERSION_CODES . M ) { int hasEnableCoarseLocationPerm = checkSelfPermission ( Manifest . permission . ACCESS_COARSE_LOCATION ) ; int hasEnableFineLocationPerm = checkSelfPermission ( Manifest . permission . ACCESS_FINE_LOCATION ) ; int hasEnableExternalWritePerm = checkSelfPermission ( Manifest . permission . WRITE_EXTERNAL_STORAGE ) ; List < String > permissionToRequest = new ArrayList < > ( ) ; if ( hasEnableCoarseLocationPerm == PackageManager . PERMISSION_DENIED ) { permissionToRequest . add ( Manifest . permission . ACCESS_COARSE_LOCATION ) ; } if ( hasEnableFineLocationPerm == PackageManager . PERMISSION_DENIED ) { permissionToRequest . add ( Manifest . permission . ACCESS_FINE_LOCATION ) ; } if ( hasEnableExternalWritePerm == PackageManager . PERMISSION_DENIED ) { permissionToRequest . add ( Manifest . permission . WRITE_EXTERNAL_STORAGE ) ; } if ( ! permissionToRequest . isEmpty ( ) ) { requestPermissions ( permissionToRequest . toArray ( new String [ permissionToRequest . size ( ) ] ) , ALLOW_PERMISSIONS ) ; } else { initEvent ( ) ; } } }
this method must be called if the android version is 6 . 0 or higher . check if the app has access_location ( coarse and fine ) and write_external_storage . if the app doesn ' t have both permission , a request is prompted to the user . for more informations about permission in android 6 . 0 , please refer to https : / / developer . android . com / training / permissions / requesting . html ? hl = fr # explain
