Java Code Examples for android.content.Intent#ACTION_OPEN_DOCUMENT_TREE

The following examples show how to use android.content.Intent#ACTION_OPEN_DOCUMENT_TREE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java    From Notepad with Apache License 2.0 8 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void exportNotes() {
    filesToExport = cab.toArray();
    cab.clear();

    if(filesToExport.length == 1 || Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        fileBeingExported = 0;
        reallyExportNotes();
    } else {
        Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);

        try {
            startActivityForResult(intent, EXPORT_TREE);
        } catch (ActivityNotFoundException e) {
            showToast(R.string.error_exporting_notes);
        }
    }
}
 
Example 2
Source File: TGSafBrowserUriRequest.java    From tuxguitar with GNU Lesser General Public License v2.1 7 votes vote down vote up
public void requestUriAccessIntentInCurrentThread() {
	Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
	intent.putExtra(EXTRA_SHOW_ADVANCED, true);
	TGSafBrowserUriResult handler = new TGSafBrowserUriResult(this);

	this.callStartActivityForResult(intent, handler.getRequestCode());
}
 
Example 3
Source File: SettingsActivity.java    From Nimingban with Apache License 2.0 7 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void openDirPickerL() {
    Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
    try {
        startActivityForResult(intent, REQUEST_CODE_PICK_IMAGE_DIR_L);
    } catch (ActivityNotFoundException e) {
        Toast.makeText(getActivity(), R.string.em_cant_find_activity, Toast.LENGTH_SHORT).show();
    }
}
 
Example 4
Source File: ShareUtil.java    From openlauncher with Apache License 2.0 7 votes vote down vote up
/***
 * Request storage access. The user needs to press "Select storage" at the correct storage.
 * @param activity The activity which will receive the result from startActivityForResult
 */
public void requestStorageAccessFramework(final Activity... activity) {
    Activity a = greedyGetActivity(activity);
    if (a != null && android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
        Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION
                | Intent.FLAG_GRANT_WRITE_URI_PERMISSION
                | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION
                | Intent.FLAG_GRANT_PREFIX_URI_PERMISSION
        );
        a.startActivityForResult(intent, REQUEST_SAF);
    }
}
 
Example 5
Source File: ImportHelper.java    From Hentoid with Apache License 2.0 6 votes vote down vote up
private static Intent getFolderPickerIntent(@NonNull final Context context) {
    Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        intent.putExtra(DocumentsContract.EXTRA_PROMPT, "Allow Write Permission");
    }
    // http://stackoverflow.com/a/31334967/1615876
    intent.putExtra("android.content.extra.SHOW_ADVANCED", true);

    // Start the SAF at the specified location
    if (Build.VERSION.SDK_INT >= O && !Preferences.getStorageUri().isEmpty()) {
        DocumentFile file = DocumentFile.fromTreeUri(context, Uri.parse(Preferences.getStorageUri()));
        if (file != null)
            intent.putExtra(EXTRA_INITIAL_URI, file.getUri());
    }

    HentoidApp.LifeCycleListener.disable(); // Prevents the app from displaying the PIN lock when returning from the SAF dialog
    return intent;
}
 
Example 6
Source File: PreferencesFragment.java    From Aegis with GNU General Public License v3.0 6 votes vote down vote up
private void selectBackupsLocation() {
    Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION
            | Intent.FLAG_GRANT_WRITE_URI_PERMISSION
            | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION
            | Intent.FLAG_GRANT_PREFIX_URI_PERMISSION);

    startActivityForResult(intent, CODE_BACKUPS);
}
 
Example 7
Source File: ShareUtil.java    From memetastic with GNU General Public License v3.0 5 votes vote down vote up
/***
 * Request storage access. The user needs to press "Select storage" at the correct storage.
 * @param activity The activity which will receive the result from startActivityForResult
 */
public void requestStorageAccessFramework(final Activity... activity) {
    Activity a = greedyGetActivity(activity);
    if (a != null && android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
        Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION
                | Intent.FLAG_GRANT_WRITE_URI_PERMISSION
                | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION
                | Intent.FLAG_GRANT_PREFIX_URI_PERMISSION
        );
        a.startActivityForResult(intent, REQUEST_SAF);
    }
}
 
Example 8
Source File: FolderActivity.java    From syncthing-android with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Invoked after user clicked on the {@link mPathView} label.
 */
@SuppressLint("InlinedAPI")
private void onPathViewClick() {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        startActivityForResult(FolderPickerActivity.createIntent(this, mFolder.path, null),
            FolderPickerActivity.DIRECTORY_REQUEST_CODE);
        return;
    }

    // This has to be android.net.Uri as it implements a Parcelable.
    android.net.Uri externalFilesDirUri = FileUtils.getExternalFilesDirUri(FolderActivity.this);

    // Display storage access framework directory picker UI.
    Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
    if (externalFilesDirUri != null) {
        intent.putExtra("android.provider.extra.INITIAL_URI", externalFilesDirUri);
    }
    intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
    intent.putExtra("android.content.extra.SHOW_ADVANCED", true);
    try {
        startActivityForResult(intent, CHOOSE_FOLDER_REQUEST);
    } catch (android.content.ActivityNotFoundException e) {
        Log.e(TAG, "onPathViewClick exception, falling back to built-in FolderPickerActivity.", e);
        startActivityForResult(FolderPickerActivity.createIntent(this, mFolder.path, null),
            FolderPickerActivity.DIRECTORY_REQUEST_CODE);
    }
}
 
Example 9
Source File: CompatUtils.java    From microMathematics with GNU General Public License v3.0 5 votes vote down vote up
public static Intent getDocTreeIntent()
{
    if (isMarshMallowOrLater())
    {
        return new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
    }
    return null;
}
 
Example 10
Source File: SettingsActivity.java    From andOTP with MIT License 5 votes vote down vote up
private void requestBackupAccess() {
    Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION
            | Intent.FLAG_GRANT_WRITE_URI_PERMISSION
            | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION
            | Intent.FLAG_GRANT_PREFIX_URI_PERMISSION);

    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && settings.isBackupLocationSet())
        intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, settings.getBackupLocation());

    startActivityForResult(intent, Constants.INTENT_SETTINGS_BACKUP_LOCATION);
}
 
Example 11
Source File: ExternalStorageOpenerFragment.java    From edslite with GNU General Public License v2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void showSystemDialog()
{
    Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
    startActivityForResult(intent, REQUEST_CODE_ADD_LOCATION);
    Toast.makeText(getActivity(), R.string.select_root_folder_tip, Toast.LENGTH_LONG).show();
}
 
Example 12
Source File: Api29MigrationActivity.java    From Hentoid with Apache License 2.0 5 votes vote down vote up
private void selectHentoidFolder() {
    Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        intent.putExtra(DocumentsContract.EXTRA_PROMPT, "Allow Write Permission");
    }
    // http://stackoverflow.com/a/31334967/1615876
    intent.putExtra("android.content.extra.SHOW_ADVANCED", true);

    startActivityForResult(intent, RQST_STORAGE_PERMISSION);
}
 
Example 13
Source File: FragmentBase.java    From FairEmail with GNU General Public License v3.0 5 votes vote down vote up
private void onStoreAttachments(Intent intent) {
    message = intent.getLongExtra("id", -1);
    Intent tree = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
    Helper.openAdvanced(tree);
    PackageManager pm = getContext().getPackageManager();
    if (tree.resolveActivity(pm) == null) // system whitelisted
        ToastEx.makeText(getContext(), R.string.title_no_saf, Toast.LENGTH_LONG).show();
    else
        startActivityForResult(Helper.getChooser(getContext(), tree), REQUEST_ATTACHMENTS);
}
 
Example 14
Source File: SAFUtil.java    From VinylMusicPlayer with GNU General Public License v3.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static void openTreePicker(Activity activity) {
    Intent i = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
    i.putExtra("android.content.extra.SHOW_ADVANCED", true);
    activity.startActivityForResult(i, SAFUtil.REQUEST_SAF_PICK_TREE);
}
 
Example 15
Source File: SAFUtil.java    From VinylMusicPlayer with GNU General Public License v3.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static void openTreePicker(Fragment fragment) {
    Intent i = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
    i.putExtra("android.content.extra.SHOW_ADVANCED", true);
    fragment.startActivityForResult(i, SAFUtil.REQUEST_SAF_PICK_TREE);
}
 
Example 16
Source File: DocumentTreeLocationsListFragment.java    From edslite with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected void addNewLocation(String locationType)
{
    Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
    startActivityForResult(intent, REQUEST_CODE_ADD_LOCATION);
}
 
Example 17
Source File: SettingsFragment.java    From Augendiagnose with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Trigger the storage access framework to access the base folder of the ext sd card.
 *
 * @param code The request code to be used.
 */
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
private void triggerStorageAccessFramework(final int code) {
	Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
	startActivityForResult(intent, code);
}
 
Example 18
Source File: MainActivityHelper.java    From PowerFileExplorer with GNU General Public License v3.0 4 votes vote down vote up
private static void triggerStorageAccessFramework(final ThemedActivity mainActivity) {
    Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
    mainActivity.startActivityForResult(intent, ThemedActivity.FROM_PREVIOUS_IO_ACTION);
}
 
Example 19
Source File: SAFUtils.java    From libcommon with Apache License 2.0 2 votes vote down vote up
/**
 * requestStorageAccessの下請け
 * @return
 */
private static Intent prepareStorageAccessPermission() {
	return new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
}
 
Example 20
Source File: SAFUtils.java    From libcommon with Apache License 2.0 2 votes vote down vote up
/**
 * requestStorageAccessの下請け
 * ドキュメントツリーへのアクセスのためのIntentを返す
 * @return
 */
private static Intent prepareStorageAccessPermission() {
	return new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
}