src/main/java/de/blau/android/util/SelectFile.java
/**
     * @param activity activity activity that called us
     * @param directoryPrefKey string resources for shared preferences for preferred (last) directory
     * @param readFile callback callback that does the actual saving, should call
     *            {@link #savePref(Preferences, int, Uri)}
     */
@param activity activity activity that called us
@param directoryPrefKey string resources for shared preferences for preferred (last) directory
@param readFile callback callback that does the actual saving, should call
#savePref(Preferences, int, Uri)
@param activity activity activity that called us @param directoryPrefKey string resources for shared preferences for preferred ( last ) directory @param readFile callback callback that does the actual saving should call #savePref ( Preferences int Uri )
public static void read(@NonNull FragmentActivity activity, int directoryPrefKey, @NonNull ReadFile readFile) {
        synchronized (readCallbackLock) {
            readCallback = readFile;
            SelectFile.activity = activity;
        }
        Preferences prefs = new Preferences(activity);
        String path = prefs.getString(directoryPrefKey);
        Intent i;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            i = new Intent(Intent.ACTION_OPEN_DOCUMENT);
            i.setType("*/*");
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && path != null) {
                i.putExtra(DocumentsContract.EXTRA_INITIAL_URI, Uri.parse(path));
            }
        } else {
            i = new Intent(activity, ThemedFilePickerActivity.class);
            i.putExtra(AbstractFilePickerActivity.EXTRA_ALLOW_MULTIPLE, false);
            i.putExtra(AbstractFilePickerActivity.EXTRA_SINGLE_CLICK, true);
            i.putExtra(AbstractFilePickerActivity.EXTRA_MODE, AbstractFilePickerActivity.MODE_FILE);
            if (path != null) {
                i.putExtra(AbstractFilePickerActivity.EXTRA_START_PATH, path);
            } else {
                try {
                    i.putExtra(AbstractFilePickerActivity.EXTRA_START_PATH, FileUtil.getPublicDirectory().getPath());
                } catch (IOException e) {
                    Log.d(DEBUG_TAG, "falling back to standard dir instead");
                    i.putExtra(AbstractFilePickerActivity.EXTRA_START_PATH, Environment.getExternalStorageDirectory().getPath());
                }
            }
        }
        activity.startActivityForResult(i, READ_FILE);
    }
public static void read ( @ NonNull FragmentActivity activity , int directoryPrefKey , @ NonNull ReadFile readFile ) { synchronized ( readCallbackLock ) { readCallback = readFile ; SelectFile . activity = activity ; } Preferences prefs = new Preferences ( activity ) ; String path = prefs . getString ( directoryPrefKey ) ; Intent i ; if ( Build . VERSION . SDK_INT >= Build . VERSION_CODES . KITKAT ) { i = new Intent ( Intent . ACTION_OPEN_DOCUMENT ) ; i . setType ( "*/*" ) ; if ( Build . VERSION . SDK_INT >= Build . VERSION_CODES . O && path != null ) { i . putExtra ( DocumentsContract . EXTRA_INITIAL_URI , Uri . parse ( path ) ) ; } } else { i = new Intent ( activity , ThemedFilePickerActivity . class ) ; i . putExtra ( AbstractFilePickerActivity . EXTRA_ALLOW_MULTIPLE , false ) ; i . putExtra ( AbstractFilePickerActivity . EXTRA_SINGLE_CLICK , true ) ; i . putExtra ( AbstractFilePickerActivity . EXTRA_MODE , AbstractFilePickerActivity . MODE_FILE ) ; if ( path != null ) { i . putExtra ( AbstractFilePickerActivity . EXTRA_START_PATH , path ) ; } else { try { i . putExtra ( AbstractFilePickerActivity . EXTRA_START_PATH , FileUtil . getPublicDirectory ( ) . getPath ( ) ) ; } catch ( IOException e ) { Log . d ( DEBUG_TAG , "falling back to standard dir instead" ) ; i . putExtra ( AbstractFilePickerActivity . EXTRA_START_PATH , Environment . getExternalStorageDirectory ( ) . getPath ( ) ) ; } } } activity . startActivityForResult ( i , READ_FILE ) ; }
@param activity activity activity that called us
 @param directoryPrefKey string resources for shared preferences for preferred (last) directory
 @param readFile callback callback that does the actual saving, should call
            {@link #savePref(Preferences, int, Uri)}
@param activity activity activity that called us @param directoryPrefKey string resources for shared preferences for preferred ( last ) directory @param readFile callback callback that does the actual saving should call { @link #savePref ( Preferences int Uri ) }
// if for whatever reason the above doesn't work we use the standard directory