question: 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 ( ) ; } } }
target:  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