List of usage examples for android.content Intent ACTION_OPEN_DOCUMENT_TREE
String ACTION_OPEN_DOCUMENT_TREE
To view the source code for android.content Intent ACTION_OPEN_DOCUMENT_TREE.
Click Source Link
From source file:android.support.tests.GrantActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE); startActivityForResult(intent, 12);/*from w w w. ja va 2 s. c o m*/ }
From source file:com.example.android.directoryselection.DirectorySelectionFragment.java
@Override public void onViewCreated(View rootView, Bundle savedInstanceState) { super.onViewCreated(rootView, savedInstanceState); rootView.findViewById(R.id.button_open_directory).setOnClickListener(new View.OnClickListener() { @Override/* ww w. j av a 2s .co m*/ public void onClick(View v) { Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE); startActivityForResult(intent, REQUEST_CODE_OPEN_DIRECTORY); } }); mCurrentDirectoryTextView = (TextView) rootView.findViewById(R.id.textview_current_directory); mCreateDirectoryButton = (Button) rootView.findViewById(R.id.button_create_directory); mCreateDirectoryButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final EditText editView = new EditText(getActivity()); new AlertDialog.Builder(getActivity()).setTitle(R.string.create_directory).setView(editView) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { createDirectory(mCurrentDirectoryUri, editView.getText().toString()); updateDirectoryEntries(mCurrentDirectoryUri); } }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { } }).show(); } }); mRecyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerview_directory_entries); mLayoutManager = mRecyclerView.getLayoutManager(); mRecyclerView.scrollToPosition(0); mAdapter = new DirectoryEntryAdapter(new ArrayList<DirectoryEntry>()); mRecyclerView.setAdapter(mAdapter); }
From source file:com.github.chenxiaolong.dualbootpatcher.FileUtils.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private static Intent buildSafOpenDocumentTreeIntent() { Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE); setCommonNativeSafOptions(intent);/*from w ww. j av a 2 s . c o m*/ return intent; }
From source file:com.theelix.libreexplorer.FileManager.java
/** * This Method use the file set by prepareCopy or PrepareCut and then paste the files *///from w w w.j a v a 2 s.co m public static void preparePaste() { //If we are running KK or later, show the "Choose Folder" dialog if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && getCurrentDirectory().getPath().contains(System.getenv("SECONDARY_STORAGE"))) { AlertDialog.Builder builder = new AlertDialog.Builder(mContext); builder.setMessage( "As Android 5.0, a new system is used for writing files to External Storage. Please press OK and Select THE EXACT FOLDER you pasted the files"); builder.setPositiveButton(mContext.getString(R.string.dialog_ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE); ((Activity) mContext).startActivityForResult(intent, REQUEST_GET_DOCUMENT); } }); builder.create().show(); } else { createDestFiles(); } }
From source file:freed.ActivityAbstract.java
@Override public void ChooseSDCard(I_OnActivityResultCallback callback) { try {//from w w w . j a va2 s . c o m resultCallback = callback; Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE); startActivityForResult(intent, READ_REQUEST_CODE); } catch (ActivityNotFoundException activityNotFoundException) { activityNotFoundException.printStackTrace(); } }
From source file:io.v.android.apps.syncslides.DeckChooserFragment.java
/** * Import a deck so it shows up in the list of all decks. *///from w w w . j a va 2s.co m private void onImportDeck() { Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE); startActivityForResult(intent, REQUEST_CODE_IMPORT_DECK); }
From source file:ml.puredark.hviewer.ui.fragments.SettingFragment.java
@Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); getPreferenceManager().setSharedPreferencesName(SharedPreferencesUtil.FILE_NAME); addPreferencesFromResource(R.xml.preferences); String downloadPath = DownloadManager.getDownloadPath(); if (downloadPath != null) { String displayPath = Uri.decode(downloadPath); getPreferenceManager().findPreference(KEY_PREF_DOWNLOAD_PATH).setSummary(displayPath); }//from w ww. java 2s . c om ListPreference listPreference = (ListPreference) getPreferenceManager() .findPreference(KEY_PREF_VIEW_DIRECTION); CharSequence[] entries = listPreference.getEntries(); int i = listPreference.findIndexOfValue(listPreference.getValue()); i = (i <= 0) ? 0 : i; listPreference.setSummary(entries[i]); listPreference.setOnPreferenceChangeListener(this); listPreference = (ListPreference) getPreferenceManager().findPreference(KEY_PREF_VIEW_VIDEO_PLAYER); entries = listPreference.getEntries(); i = listPreference.findIndexOfValue(listPreference.getValue()); i = (i <= 0) ? 0 : i; listPreference.setSummary(entries[i]); listPreference.setOnPreferenceChangeListener(this); getPreferenceScreen().setOnPreferenceChangeListener(this); final DirectoryChooserConfig config = DirectoryChooserConfig.builder() .initialDirectory((downloadPath.startsWith("/")) ? downloadPath : DownloadManager.DEFAULT_PATH) .newDirectoryName("download").allowNewDirectoryNameModification(true).build(); mDialog = DirectoryChooserFragment.newInstance(config); mDialog.setTargetFragment(this, 0); float size = (float) Fresco.getImagePipelineFactory().getMainFileCache().getSize() / ByteConstants.MB; Preference cacheCleanPreference = getPreferenceManager().findPreference(KEY_PREF_CACHE_CLEAN); cacheCleanPreference.setSummary(String.format(" %.2f MB", size)); LongClickPreference prefDownloadPath = (LongClickPreference) getPreferenceManager() .findPreference(KEY_PREF_DOWNLOAD_PATH); prefDownloadPath.setOnLongClickListener(v -> { new AlertDialog.Builder(activity).setTitle("?") .setItems(new String[] { "", "" }, (dialogInterface, pos) -> { if (pos == 0 && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE); intent.addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION); try { startActivityForResult(intent, RESULT_CHOOSE_DIRECTORY); } catch (ActivityNotFoundException e) { e.printStackTrace(); mDialog.show(getFragmentManager(), null); } new Handler().postDelayed(() -> { if (!opened) activity.showSnackBar( "?"); }, 1000); } else if (pos == 1) { mDialog.show(getFragmentManager(), null); } else activity.showSnackBar("???"); }) .setNegativeButton(getString(R.string.cancel), null).show(); return true; }); }
From source file:com.filemanager.free.utils.MainActivityHelper.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private void triggerStorageAccessFramework() { Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE); mainActivity.startActivityForResult(intent, 3); }
From source file:de.k3b.android.toGoZip.SettingsActivity.java
private boolean openPicker(CharSequence oldFolder, int folderpickerCode, boolean useDocumentProvider) { if (!useDocumentProvider) { Intent intent = new Intent(SettingsActivity.this, FolderPicker.class); if ((oldFolder != null) && (oldFolder.length() > 0)) { intent.putExtra("location", oldFolder); // initial dir }//from www . j a v a 2s. c om startActivityForResult(intent, folderpickerCode); } else { Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE); intent.setFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION); startActivityForResult(intent, folderpickerCode); } return true; }
From source file:be.ppareit.swiftp.gui.PreferenceFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity()); Resources resources = getResources(); TwoStatePreference runningPref = findPref("running_switch"); updateRunningState();/*from w ww . j av a 2s .c o m*/ runningPref.setOnPreferenceChangeListener((preference, newValue) -> { if ((Boolean) newValue) { startServer(); } else { stopServer(); } return true; }); PreferenceScreen prefScreen = findPref("preference_screen"); Preference marketVersionPref = findPref("market_version"); marketVersionPref.setOnPreferenceClickListener(preference -> { // start the market at our application Intent intent = new Intent(Intent.ACTION_VIEW); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setData(Uri.parse("market://details?id=be.ppareit.swiftp")); try { // this can fail if there is no market installed startActivity(intent); } catch (Exception e) { Cat.e("Failed to launch the market."); e.printStackTrace(); } return false; }); if (!App.isFreeVersion()) { prefScreen.removePreference(marketVersionPref); } updateLoginInfo(); EditTextPreference usernamePref = findPref("username"); usernamePref.setOnPreferenceChangeListener((preference, newValue) -> { String newUsername = (String) newValue; if (preference.getSummary().equals(newUsername)) return false; if (!newUsername.matches("[a-zA-Z0-9]+")) { Toast.makeText(getActivity(), R.string.username_validation_error, Toast.LENGTH_LONG).show(); return false; } stopServer(); return true; }); mPassWordPref = findPref("password"); mPassWordPref.setOnPreferenceChangeListener((preference, newValue) -> { stopServer(); return true; }); mAutoconnectListPref = findPref("autoconnect_preference"); mAutoconnectListPref.setOnPopulateListener(pref -> { Cat.d("autoconnect populate listener"); WifiManager wifiManager = (WifiManager) getActivity().getApplicationContext() .getSystemService(Context.WIFI_SERVICE); List<WifiConfiguration> configs = wifiManager.getConfiguredNetworks(); if (configs == null) { Cat.e("Unable to receive wifi configurations, bark at user and bail"); Toast.makeText(getActivity(), R.string.autoconnect_error_enable_wifi_for_access_points, Toast.LENGTH_LONG).show(); return; } CharSequence[] ssids = new CharSequence[configs.size()]; CharSequence[] niceSsids = new CharSequence[configs.size()]; for (int i = 0; i < configs.size(); ++i) { ssids[i] = configs.get(i).SSID; String ssid = configs.get(i).SSID; if (ssid.length() > 2 && ssid.startsWith("\"") && ssid.endsWith("\"")) { ssid = ssid.substring(1, ssid.length() - 1); } niceSsids[i] = ssid; } pref.setEntries(niceSsids); pref.setEntryValues(ssids); }); mAutoconnectListPref.setOnPreferenceClickListener(preference -> { Cat.d("Clicked"); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_DENIED) { if (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION)) { new AlertDialog.Builder(getContext()).setTitle(R.string.request_coarse_location_dlg_title) .setMessage(R.string.request_coarse_location_dlg_message) .setPositiveButton(android.R.string.ok, (dialog, which) -> { requestPermissions(new String[] { Manifest.permission.ACCESS_COARSE_LOCATION }, ACCESS_COARSE_LOCATION_REQUEST_CODE); }).setOnCancelListener(dialog -> { mAutoconnectListPref.getDialog().cancel(); }).create().show(); } else { requestPermissions(new String[] { Manifest.permission.ACCESS_COARSE_LOCATION }, ACCESS_COARSE_LOCATION_REQUEST_CODE); } } } return false; }); EditTextPreference portnum_pref = findPref("portNum"); portnum_pref.setSummary(sp.getString("portNum", resources.getString(R.string.portnumber_default))); portnum_pref.setOnPreferenceChangeListener((preference, newValue) -> { String newPortnumString = (String) newValue; if (preference.getSummary().equals(newPortnumString)) return false; int portnum = 0; try { portnum = Integer.parseInt(newPortnumString); } catch (Exception e) { Cat.d("Error parsing port number! Moving on..."); } if (portnum <= 0 || 65535 < portnum) { Toast.makeText(getActivity(), R.string.port_validation_error, Toast.LENGTH_LONG).show(); return false; } preference.setSummary(newPortnumString); stopServer(); return true; }); Preference chroot_pref = findPref("chrootDir"); chroot_pref.setSummary(FsSettings.getChrootDirAsString()); chroot_pref.setOnPreferenceClickListener(preference -> { AlertDialog folderPicker = new FolderPickerDialogBuilder(getActivity(), FsSettings.getChrootDir()) .setSelectedButton(R.string.select, path -> { if (preference.getSummary().equals(path)) return; if (!FsSettings.setChrootDir(path)) return; // TODO: this is a hotfix, create correct resources, improve UI/UX final File root = new File(path); if (!root.canRead()) { Toast.makeText(getActivity(), "Notice that we can't read/write in this folder.", Toast.LENGTH_LONG).show(); } else if (!root.canWrite()) { Toast.makeText(getActivity(), "Notice that we can't write in this folder, reading will work. Writing in sub folders might work.", Toast.LENGTH_LONG).show(); } preference.setSummary(path); stopServer(); }).setNegativeButton(R.string.cancel, null).create(); folderPicker.show(); return true; }); final CheckBoxPreference wakelock_pref = findPref("stayAwake"); wakelock_pref.setOnPreferenceChangeListener((preference, newValue) -> { stopServer(); return true; }); final CheckBoxPreference writeExternalStorage_pref = findPref("writeExternalStorage"); String externalStorageUri = FsSettings.getExternalStorageUri(); if (externalStorageUri == null) { writeExternalStorage_pref.setChecked(false); } writeExternalStorage_pref.setOnPreferenceChangeListener((preference, newValue) -> { if ((boolean) newValue) { Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE); startActivityForResult(intent, ACTION_OPEN_DOCUMENT_TREE); return false; } else { FsSettings.setExternalStorageUri(null); return true; } }); ListPreference theme = findPref("theme"); theme.setSummary(theme.getEntry()); theme.setOnPreferenceChangeListener((preference, newValue) -> { theme.setSummary(theme.getEntry()); getActivity().recreate(); return true; }); Preference help = findPref("help"); help.setOnPreferenceClickListener(preference -> { Cat.v("On preference help clicked"); Context context = getActivity(); AlertDialog ad = new AlertDialog.Builder(context).setTitle(R.string.help_dlg_title) .setMessage(R.string.help_dlg_message).setPositiveButton(android.R.string.ok, null).create(); ad.show(); Linkify.addLinks((TextView) ad.findViewById(android.R.id.message), Linkify.ALL); return true; }); Preference about = findPref("about"); about.setOnPreferenceClickListener(preference -> { startActivity(new Intent(getActivity(), AboutActivity.class)); return true; }); }