Android java select directory

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Selecting directories/files made a lot easier.

License

singhangadin/android-filepicker

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

Readme.md

The project is no longer being maintained.

Super Lite Android Library to select files/directories from Device Storage.

Read all about internal classes and functions in the wiki.

  • Easy to Implement.
  • No permissions required.
  • Files, Directory Selection.
  • Single or Multiple File selection.
compile 'com.github.angads25:filepicker:1.1.1'
DialogProperties properties = new DialogProperties();
properties.selection_mode = DialogConfigs.SINGLE_MODE; properties.selection_type = DialogConfigs.FILE_SELECT; properties.root = new File(DialogConfigs.DEFAULT_DIR); properties.error_dir = new File(DialogConfigs.DEFAULT_DIR); properties.offset = new File(DialogConfigs.DEFAULT_DIR); properties.extensions = null;
FilePickerDialog dialog = new FilePickerDialog(MainActivity.this,properties); dialog.setTitle("Select a File");
dialog.setDialogSelectionListener(new DialogSelectionListener() < @Override public void onSelectedFilePaths(String[] files) < //files is the array of the paths of files selected by the Application User. > >);

Marshmallow and above requests for the permission on runtime. You should override onRequestPermissionsResult in Activity/AppCompatActivity class and show the dialog only if permissions have been granted.

//Add this method to show Dialog when the required permission has been granted to the app. @Override public void onRequestPermissionsResult(int requestCode,@NonNull String permissions[],@NonNull int[] grantResults) < switch (requestCode) < case FilePickerDialog.EXTERNAL_READ_PERMISSION_GRANT: < if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) < if(dialog!=null) < //Show dialog if the read permission has been granted. dialog.show(); > > else < //Permission has not been granted. Notify the user. Toast.makeText(MainActivity.this,"Permission is Required for getting list of files",Toast.LENGTH_SHORT).show(); > > > >
That's It. You are good to proceed further. 
com.github.angads25.filepicker.view.FilePickerPreference xmlns:app="http://schemas.android.com/apk/res-auto" android:key="your_preference_key" android:title="Pick a Directory" android:summary="Just a Summary" android:defaultValue="/sdcard:/mnt" app:titleText="Select Directories" app:error_dir="/mnt" app:root_dir="/sdcard" app:selection_mode="multi_mode" app:selection_type="dir_select" app:extensions="txt:pdf:"/>
@Override public boolean onPreferenceChange(Preference preference, Object o) < if(preference.getKey().equals("your_preference_key")) < . >return false; >
@Override public boolean onPreferenceChange(Preference preference, Object o) < if(preference.getKey().equals("your_preference_key")) < String value=(String)o; String arr[]=value.split(":"); . . > return false; >
  • defaultValue , error_dir , root_dir , offset_dir must have valid directory/file paths.
  • defaultValue paths should end with ‘:’.
  • defaultValue can have multiple paths, there should be a ‘:’ between two paths.
  • extensions must not have ‘.’.
  • extensions should end with ‘:’ , also have ‘:’ between two extensions. eg. /sdcard:/mnt:
Читайте также:  What is generic type in java

FilePickerPreference stores selected directories/files as a String . It delimits multiple files/directories using ‘:’ char .

Read more on implementation here.

Screenshot 1

Screenshot 2

Screenshot 3

Screenshot 4

Screenshot 5

Performance 1

Performance 2

Copyright (C) 2016 Angad Singh Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 

About

Selecting directories/files made a lot easier.

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

A directory chooser library for Android.

License

passy/Android-DirectoryChooser

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Читайте также:  Html drag and drop online

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

A simple directory chooser you can integrate into your Android app.

This version of the library has no additional dependencies, but requires Android v11+ to work. There is, however, a pre-v11-branch that supports down to v7 using ActionBarSherlock.

You can download the sample app from the Play Store:

Get it on Google Play

Based on the DirectoryChooser from the excellent AntennaPod App by danieloeh.

As stand-alone Activity
As DialogFragment

For a full example see the sample app in the repository.

Library releases are available on Maven Central, snapshots can be retrieved from Sonatype:

compile 'net.rdrei.android.dirchooser:library:3.2@aar'
dependency> groupId>net.rdrei.android.dirchoosergroupId> artifactId>libraryartifactId> version>3.2version> type>aartype> dependency>
compile 'net.rdrei.android.dirchooser:library:1.0-pre-v11@aar'
dependency> groupId>net.rdrei.android.dirchoosergroupId> artifactId>libraryartifactId> version>1.0-pre-v11version> type>aartype> dependency>
compile 'net.rdrei.android.dirchooser:library:3.2-SNAPSHOT@aar'
compile 'net.rdrei.android.dirchooser:library:2.0-pre-v11-SNAPSHOT@aar'

Alternatively, check out this repository and add it as a library project.

$ git clone https://github.com/passy/Android-DirectoryChooser.git

Import the project into your favorite IDE and add android.library.reference.1=/path/to/Android-DirectoryChooser/library to your project.properties .

You need to declare the DirectoryChooserActivity and request the android.permission.WRITE_EXTERNAL_STORAGE permission.

uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> . application> activity android:name="net.rdrei.android.dirchooser.DirectoryChooserActivity" /> application>

To choose a directory, start the activity from your app logic:

final Intent chooserIntent = new Intent(this, DirectoryChooserActivity.class); final DirectoryChooserConfig config = DirectoryChooserConfig.builder() .newDirectoryName("DirChooserSample") .allowReadOnlyDirectory(true) .allowNewDirectoryNameModification(true) .build(); chooserIntent.putExtra(DirectoryChooserActivity.EXTRA_CONFIG, config); // REQUEST_DIRECTORY is a constant integer to identify the request, e.g. 0 startActivityForResult(chooserIntent, REQUEST_DIRECTORY);

Handle the result in your onActivityResult method:

@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) < super.onActivityResult(requestCode, resultCode, data); if (requestCode == REQUEST_DIRECTORY) < if (resultCode == DirectoryChooserActivity.RESULT_CODE_DIR_SELECTED) < handleDirectoryChoice(data .getStringExtra(DirectoryChooserActivity.RESULT_SELECTED_DIR)); > else < // Nothing selected > > >

You can also use the underlying DialogFragment for even better integration. Whether you use the Fragment as a Dialog or not is completely up to you. All you have to do is implement the OnFragmentInteractionListener interface to respond to the events that a directory is selected or the user cancels the dialog:

public class DirChooserFragmentSample extends Activity implements DirectoryChooserFragment.OnFragmentInteractionListener < private TextView mDirectoryTextView; private DirectoryChooserFragment mDialog; @Override protected void onCreate(Bundle savedInstanceState) < super.onCreate(savedInstanceState); setContentView(R.layout.dialog); final DirectoryChooserConfig config = DirectoryChooserConfig.builder() .newDirectoryName("DialogSample") .build(); mDialog = DirectoryChooserFragment.newInstance(config); mDirectoryTextView = (TextView) findViewById(R.id.textDirectory); findViewById(R.id.btnChoose) .setOnClickListener(new View.OnClickListener() < @Override public void onClick(View v) < mDialog.show(getFragmentManager(), null); > >); > @Override public void onSelectDirectory(@NonNull String path) < mDirectoryTextView.setText(path); mDialog.dismiss(); > @Override public void onCancelChooser() < mDialog.dismiss(); > >

If calling the directory chooser from your own fragment, be sure to set the target fragment first:

@Override public void onClick(View v) < mDialog.setTargetFragment(this, 0); mDialog.show(getFragmentManager(), null); >

The Directory Chooser is configured through a parcelable configuration object, which is great because it means that you don’t have to tear your hair out over finicky string extras. Instead, you get auto-completion and a nice immutable data structure. Here’s what you can configure:

Читайте также:  Вывести часовой пояс php

newDirectoryName : String (required)

Name of the directory to create. User can change this name when he creates the folder. To avoid this use allowNewDirectoryNameModification argument.

initialDirectory : String (default: «»)

Optional argument to define the path of the directory that will be shown first. If it is not sent or if path denotes a non readable/writable directory or it is not a directory, it defaults to android.os.Environment#getExternalStorageDirectory() .

allowReadOnlyDirectory : Boolean (default: false)

Argument to define whether or not the directory chooser allows read-only paths to be chosen. If it false only directories with read-write access can be chosen.

allowNewDirectoryNameModification : Boolean (default: false)

Argument to define whether or not the directory chooser allows modification of provided new directory name.

final DirectoryChooserConfig config = DirectoryChooserConfig.builder() .newDirectoryName("DialogSample") .allowNewDirectoryNameModification(true) .allowReadOnlyDirectory(true) .initialDirectory("/sdcard") .build();

Источник

Оцените статью