Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
abbasalim authored Sep 12, 2018
1 parent 7637d52 commit aefab7a
Showing 1 changed file with 14 additions and 29 deletions.
43 changes: 14 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,39 +22,24 @@ dependencies {
Open file picker:

```java
new MaterialFilePicker()
.withActivity(this)
.withRequestCode(1)
.withFilter(Pattern.compile(".*\\.txt$")) // Filtering files and directories by file name using regexp
.withFilterDirectories(true) // Set directories filterable (false by default)
.withHiddenFiles(true) // Show hidden files and folders
.start();
DirectoryFragment instance = new DirectoryFragment();
Bundle args = new Bundle();
args.putString(DirectoryFragment.ARG_FILE_PATH, Environment.getExternalStorageDirectory().getAbsolutePath());
args.putSerializable(DirectoryFragment.ARG_FILTER, new CompositeFilter(new ArrayList<FileFilter>()));
args.putBoolean(DirectoryFragment.ARG_SHOW_HIDDEN, false);
instance.setArguments(args);
instance.show(getSupportFragmentManager(), "AnyTag");
DirectoryFragment.FileClickListener f = new DirectoryFragment.FileClickListener() {
@Override
public void onFileClicked(File clickedFile) {
Toast.makeText(MainActivity.this, "فایل انتخاب شد", Toast.LENGTH_SHORT).show();
}
};
instance.setInterFace(f);
```
or
```java
Intent intent = new Intent(this, FilePickerActivity.class);
intent.putExtra(FilePickerActivity.ARG_FILE_FILTER, Pattern.compile(".*\\.txt$"));
intent.putExtra(FilePickerActivity.ARG_DIRECTORIES_FILTER, true);
intent.putExtra(FilePickerActivity.ARG_SHOW_HIDDEN, true);
startActivityForResult(intent, 1);
```

Override on activity result:

```java
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

if (requestCode == 1 && resultCode == RESULT_OK) {
String filePath = data.getStringExtra(FilePickerActivity.RESULT_FILE_PATH);
// Do anything with file
}
}
```

Runtime permissions:

You should handle runtime permissions in activity, from what you called Material File Picker.
Look [here](https://github.com/nbsp-team/MaterialFilePicker/blob/master/app/src/main/java/com/dimorinny/sample/MainActivity.java#L38-L69) for example code.

0 comments on commit aefab7a

Please sign in to comment.