src/main/java/de/blau/android/util/ContentResolverUtil.java
/**
     * Persist file access permissions if possible
     * 
     * @param context an Android Context
     * @param intentFlags the flags from the Intent
     * @param uri the Uri
     * @return true if things seemed to work
     */
Persist file access permissions if possible

@param context an Android Context
@param intentFlags the flags from the Intent
@param uri the Uri
@return true if things seemed to work
Persist file access permissions if possible @param context an Android Context @param intentFlags the flags from the Intent @param uri the Uri @return true if things seemed to work
public static boolean persistPermissions(@NonNull Context context, int intentFlags, @NonNull Uri uri) {
        if ((intentFlags & Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION) != 0) { 
            Log.d(DEBUG_TAG, "Persisting permissions for " + uri);
            try {
                context.getContentResolver().takePersistableUriPermission(uri,
                        intentFlags & (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION));
                return true;
            } catch (Exception ex) {
                Log.e(DEBUG_TAG, "Unable to persist read permission for " + uri);
                Snack.toastTopWarning(context, R.string.toast_unable_to_persist_permissions);
            }
        }
        return false;
    }
public static boolean persistPermissions ( @ NonNull Context context , int intentFlags , @ NonNull Uri uri ) { if ( ( intentFlags & Intent . FLAG_GRANT_PERSISTABLE_URI_PERMISSION ) != 0 ) { Log . d ( DEBUG_TAG , "Persisting permissions for " + uri ) ; try { context . getContentResolver ( ) . takePersistableUriPermission ( uri , intentFlags & ( Intent . FLAG_GRANT_READ_URI_PERMISSION | Intent . FLAG_GRANT_WRITE_URI_PERMISSION ) ) ; return true ; } catch ( Exception ex ) { Log . e ( DEBUG_TAG , "Unable to persist read permission for " + uri ) ; Snack . toastTopWarning ( context , R . string . toast_unable_to_persist_permissions ) ; } } return false ; }
Persist file access permissions if possible
Persist file access permissions if possible
// this will never be the case pre-API 19