Skip to content

Commit 153c6d7

Browse files
Added partial support to Android13
1 parent 6a57686 commit 153c6d7

File tree

8 files changed

+228
-269
lines changed

8 files changed

+228
-269
lines changed

Readme.md

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
![](https://github.com/TutorialsAndroid/FilePicker/blob/master/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png)
22

3-
# FilePicker ![API](https://img.shields.io/badge/API-21%2B-brightgreen.svg?style=flat) [![License](https://img.shields.io/badge/License-Apache%202.0-orange.svg)](https://opensource.org/licenses/Apache-2.0) [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-FilePicker-yellow.svg?style=flat)](https://android-arsenal.com/details/1/7663) [![](https://jitpack.io/v/TutorialsAndroid/FilePicker.svg)](https://jitpack.io/#TutorialsAndroid/FilePicker)
3+
# FilePicker ![API](https://img.shields.io/badge/API-21%2B-brightgreen.svg?style=flat) [![License](https://img.shields.io/badge/License-Apache%202.0-orange.svg)](https://opensource.org/licenses/Apache-2.0) [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-FilePicker-yellow.svg?style=flat)](https://android-arsenal.com/details/1/7663) [![](https://jitpack.io/v/TutorialsAndroid/FilePicker.svg)](https://jitpack.io/#TutorialsAndroid/FilePicker) [![](https://img.shields.io/badge/Instagram-E4405F?style=for-the-badge&logo=instagram&logoColor=white)](https://instagram.com/a.masram444) [![](https://img.shields.io/badge/Telegram-2CA5E0?style=for-the-badge&logo=telegram&logoColor=white)](https://t.me/a_masram444)
44
Android Library to select files/directories from Device Storage
55

6-
## And Don't Forget To Follow Me On Instagram
7-
8-
<p align="center">Follow me on instagram to stay up-to-date https://instagram.com/a.masram444
9-
106
## Contributors
117

128
[M&R Games](https://github.com/mrgames13)
@@ -17,7 +13,7 @@ Android Library to select files/directories from Device Storage
1713

1814
[![](https://jitpack.io/v/TutorialsAndroid/FilePicker.svg)](https://jitpack.io/#TutorialsAndroid/FilePicker)
1915

20-
`Latest version of this library is migrated to androidx`
16+
`Latest version of this library is migrated to androidx and Added partial Support to Android 13.`
2117

2218
### Screenshot
2319

@@ -26,11 +22,10 @@ Android Library to select files/directories from Device Storage
2622
### Features
2723

2824
* Easy to Implement.
29-
* No permissions required.
3025
* Files, Directory Selection.
3126
* Single or Multiple File selection.
3227

33-
### Installation
28+
### Installation with JitPack
3429

3530
Add it in your root build.gradle at the end of repositories:
3631

@@ -43,13 +38,14 @@ Add it in your root build.gradle at the end of repositories:
4338
Step 2. Add the dependency
4439

4540
dependencies {
46-
implementation 'com.github.TutorialsAndroid:FilePicker:v9.0.1'
41+
implementation 'com.github.TutorialsAndroid:FilePicker:v9.1.3'
4742
}
4843

49-
Step 3. Or instead of using jitpack you can use ```mavenCentral()```
44+
### Installation with mavenCentral()
45+
Step 1. Directly add the dependency in application build.gradle file:
5046

5147
dependencies {
52-
implementation 'io.github.tutorialsandroid:filepicker:9.0.2'
48+
implementation 'io.github.tutorialsandroid:filepicker:9.1.3'
5349
}
5450

5551
### Usage
@@ -65,6 +61,25 @@ Step 3. Or instead of using jitpack you can use ```mavenCentral()```
6561
</application>
6662
</manifest>
6763
```
64+
**Also if you are targeting Android 10 or higher. You have to add permissions**
65+
66+
```xml
67+
<!-- If you are targeting apps above android version 6.0 to 12.0 You need to add this permission in your manifest -->
68+
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
69+
android:maxSdkVersion="32" />
70+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
71+
android:maxSdkVersion="32" />
72+
73+
<!-- Now if you are targeting app above android version 13.0 then you have to add this permission in your manifest.
74+
It's upon you which type of files you want to access if you want access Audio, Images and Videos files then you have
75+
to call all this below permissions -->
76+
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO"/>
77+
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>
78+
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO"/>
79+
80+
<!-- If you are targeting your app from android version 4.4 to the latest version of android then
81+
you have to call all the above permissions as mentioned -->
82+
```
6883

6984
## FilePickerDialog
7085
1. Start by creating an instance of `DialogProperties`.
@@ -90,7 +105,7 @@ Step 3. Or instead of using jitpack you can use ```mavenCentral()```
90105
3. Next create an instance of `FilePickerDialog`, and pass `Context` and `DialogProperties` references as parameters. Optional: You can change the title of dialog. Default is current directory name. Set the positive button string. Default is Select. Set the negative button string. Defalut is Cancel.
91106

92107
```java
93-
FilePickerDialog dialog = new FilePickerDialog(MainActivity.this, MainActivity.this,properties);
108+
FilePickerDialog dialog = new FilePickerDialog(MainActivity.this, properties);
94109
dialog.setTitle("Select a File");
95110
```
96111

@@ -141,7 +156,8 @@ As of Android 13 and above you can only browse and select Images,Videos and Audi
141156
Videos | READ_MEDIA_VIDEO
142157
Audio files | READ_MEDIA_AUDIO
143158
```
144-
Before you access another app's media files, verify that the user has granted the appropriate granular media permissions to your app.
159+
160+
*Before you access another app's media files, verify that the user has granted the appropriate granular media permissions to your app.*
145161

146162
If you request both the ```READ_MEDIA_IMAGES``` permission and the ```READ_MEDIA_VIDEO``` permission at the same time, only one system permission dialog appears.
147163

library/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ group='com.github.TutorialsAndroid'
44

55
ext {
66
PUBLISH_GROUP_ID = 'io.github.tutorialsandroid'
7-
PUBLISH_VERSION = '9.0.2'
7+
PUBLISH_VERSION = '9.1.3'
88
PUBLISH_ARTIFACT_ID = 'filepicker'
99
PUBLISH_DESCRIPTION = 'Android Library to select files/directories from Device Storage'
1010
PUBLISH_URL = 'https://github.com/TutorialsAndroid/FilePicker'

library/src/main/AndroidManifest.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,4 @@
77
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO"/>
88
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>
99
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO"/>
10-
<!-- <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>-->
1110
</manifest>

library/src/main/java/com/developer/filepicker/utils/Utility.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
*/
1919
public class Utility {
2020

21-
private static final int REQUEST_MEDIA_PERMISSIONS = 456;
22-
2321
public static boolean checkStorageAccessPermissions(Context context) {
2422
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
2523
String permission = "android.permission.READ_EXTERNAL_STORAGE";
@@ -32,17 +30,15 @@ public static boolean checkStorageAccessPermissions(Context context) {
3230
}
3331

3432
@android.annotation.TargetApi(Build.VERSION_CODES.TIRAMISU)
35-
public static boolean checkMediaAccessPermissions(Context context) {//, Activity activity) {
33+
public static boolean checkMediaAccessPermissions(Context context) {
3634
String audioPermission = Manifest.permission.READ_MEDIA_AUDIO;
3735
String imagesPermission = Manifest.permission.READ_MEDIA_IMAGES;
3836
String videoPermission = Manifest.permission.READ_MEDIA_VIDEO;
39-
// Check for permissions and request them if needed
37+
// Check for permissions and if permissions are granted then it will return true
4038
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
4139
// You have the permissions, you can proceed with your media file operations.
42-
// You don't have the permissions. Request them.
43-
// activity.requestPermissions(new String[]{audioPermission, imagesPermission, videoPermission}, REQUEST_MEDIA_PERMISSIONS);
44-
return context.checkSelfPermission(audioPermission) == PackageManager.PERMISSION_GRANTED &&
45-
context.checkSelfPermission(imagesPermission) == PackageManager.PERMISSION_GRANTED &&
40+
return context.checkSelfPermission(audioPermission) == PackageManager.PERMISSION_GRANTED ||
41+
context.checkSelfPermission(imagesPermission) == PackageManager.PERMISSION_GRANTED ||
4642
context.checkSelfPermission(videoPermission) == PackageManager.PERMISSION_GRANTED;
4743
}
4844
return false;

library/src/main/java/com/developer/filepicker/view/FilePickerDialog.java

Lines changed: 43 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import com.developer.filepicker.R;
2020
import com.developer.filepicker.controller.DialogSelectionListener;
21-
import com.developer.filepicker.controller.NotifyItemChecked;
2221
import com.developer.filepicker.controller.adapters.FileListAdapter;
2322
import com.developer.filepicker.model.DialogConfigs;
2423
import com.developer.filepicker.model.DialogProperties;
@@ -36,11 +35,8 @@
3635
/**
3736
* @author akshay sunil masram
3837
*/
39-
@SuppressWarnings("unused")
4038
public class FilePickerDialog extends Dialog implements AdapterView.OnItemClickListener {
41-
4239
private static final String TAG = FilePickerDialog.class.getSimpleName();
43-
4440
private final Context context;
4541
private Activity activity;
4642
private ListView listView;
@@ -57,7 +53,6 @@ public class FilePickerDialog extends Dialog implements AdapterView.OnItemClickL
5753

5854
public static final int EXTERNAL_READ_PERMISSION_GRANT = 112;
5955

60-
@Deprecated
6156
public FilePickerDialog(Context context) {
6257
super(context);
6358
this.context = context;
@@ -66,6 +61,7 @@ public FilePickerDialog(Context context) {
6661
internalList = new ArrayList<>();
6762
}
6863

64+
@Deprecated
6965
public FilePickerDialog(Activity activity, Context context) {
7066
super(context);
7167
this.activity = activity;
@@ -75,7 +71,6 @@ public FilePickerDialog(Activity activity, Context context) {
7571
internalList = new ArrayList<>();
7672
}
7773

78-
@Deprecated
7974
public FilePickerDialog(Context context, DialogProperties properties, int themeResId) {
8075
super(context, themeResId);
8176
this.context = context;
@@ -84,6 +79,7 @@ public FilePickerDialog(Context context, DialogProperties properties, int themeR
8479
internalList = new ArrayList<>();
8580
}
8681

82+
@Deprecated
8783
public FilePickerDialog(Activity activity, Context context, DialogProperties properties, int themeResId) {
8884
super(context, themeResId);
8985
this.activity = activity;
@@ -93,7 +89,6 @@ public FilePickerDialog(Activity activity, Context context, DialogProperties pro
9389
internalList = new ArrayList<>();
9490
}
9591

96-
@Deprecated
9792
public FilePickerDialog(Context context, DialogProperties properties) {
9893
super(context);
9994
this.context = context;
@@ -102,6 +97,7 @@ public FilePickerDialog(Context context, DialogProperties properties) {
10297
internalList = new ArrayList<>();
10398
}
10499

100+
@Deprecated
105101
public FilePickerDialog(Activity activity, Context context, DialogProperties properties) {
106102
super(context);
107103
this.activity = activity;
@@ -138,60 +134,49 @@ protected void onCreate(Bundle savedInstanceState) {
138134
if (negativeBtnNameStr != null) {
139135
cancel.setText(negativeBtnNameStr);
140136
}
141-
select.setOnClickListener(new View.OnClickListener() {
142-
@Override
143-
public void onClick(View view) {
144-
String[] paths = MarkedItemList.getSelectedPaths();
145-
if (callbacks != null) {
146-
callbacks.onSelectedFilePaths(paths);
147-
}
148-
dismiss();
149-
}
150-
});
151-
cancel.setOnClickListener(new View.OnClickListener() {
152-
@Override
153-
public void onClick(View view) {
154-
cancel();
137+
select.setOnClickListener(view -> {
138+
String[] paths = MarkedItemList.getSelectedPaths();
139+
if (callbacks != null) {
140+
callbacks.onSelectedFilePaths(paths);
155141
}
142+
dismiss();
156143
});
144+
cancel.setOnClickListener(view -> cancel());
157145
mFileListAdapter = new FileListAdapter(internalList, context, properties);
158-
mFileListAdapter.setNotifyItemCheckedListener(new NotifyItemChecked() {
159-
@Override
160-
public void notifyCheckBoxIsClicked() {
161-
positiveBtnNameStr = positiveBtnNameStr == null ?
162-
context.getResources().getString(R.string.choose_button_label) : positiveBtnNameStr;
163-
int size = MarkedItemList.getFileCount();
164-
if (size == 0) {
165-
select.setEnabled(false);
166-
int color;
167-
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
168-
color = context.getResources().getColor(R.color.colorAccent,
169-
context.getTheme());
170-
} else {
171-
color = context.getResources().getColor(R.color.colorAccent);
172-
}
173-
select.setTextColor(Color.argb(128, Color.red(color), Color.green(color),
174-
Color.blue(color)));
175-
select.setText(positiveBtnNameStr);
146+
mFileListAdapter.setNotifyItemCheckedListener(() -> {
147+
positiveBtnNameStr = positiveBtnNameStr == null ?
148+
context.getResources().getString(R.string.choose_button_label) : positiveBtnNameStr;
149+
int size1 = MarkedItemList.getFileCount();
150+
if (size1 == 0) {
151+
select.setEnabled(false);
152+
int color;
153+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
154+
color = context.getResources().getColor(R.color.colorAccent,
155+
context.getTheme());
176156
} else {
177-
select.setEnabled(true);
178-
int color;
179-
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
180-
color = context.getResources().getColor(R.color.colorAccent,
181-
context.getTheme());
182-
} else {
183-
color = context.getResources().getColor(R.color.colorAccent);
184-
}
185-
select.setTextColor(color);
186-
String button_label = positiveBtnNameStr + " (" + size + ") ";
187-
select.setText(button_label);
157+
color = context.getResources().getColor(R.color.colorAccent);
188158
}
189-
if (properties.selection_mode == DialogConfigs.SINGLE_MODE) {
190-
/* If a single file has to be selected, clear the previously checked
191-
* checkbox from the list.
192-
*/
193-
mFileListAdapter.notifyDataSetChanged();
159+
select.setTextColor(Color.argb(128, Color.red(color), Color.green(color),
160+
Color.blue(color)));
161+
select.setText(positiveBtnNameStr);
162+
} else {
163+
select.setEnabled(true);
164+
int color;
165+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
166+
color = context.getResources().getColor(R.color.colorAccent,
167+
context.getTheme());
168+
} else {
169+
color = context.getResources().getColor(R.color.colorAccent);
194170
}
171+
select.setTextColor(color);
172+
String button_label = positiveBtnNameStr + " (" + size1 + ") ";
173+
select.setText(button_label);
174+
}
175+
if (properties.selection_mode == DialogConfigs.SINGLE_MODE) {
176+
/* If a single file has to be selected, clear the previously checked
177+
* checkbox from the list.
178+
*/
179+
mFileListAdapter.notifyDataSetChanged();
195180
}
196181
});
197182
listView.setAdapter(mFileListAdapter);
@@ -234,17 +219,18 @@ protected void onStart() {
234219
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
235220
if (Utility.checkMediaAccessPermissions(context)) {
236221
//Permission granted...
222+
Log.d(TAG, "Permission granted");
237223
dir();
238224
} else {
239225
//Permissions are not granted...
240-
Log.d(TAG, "Permissions are not granted");
226+
Log.d(TAG, "Permissions are not granted. You need to ask permission to user before accessing the storage and showing dialog.");
241227
}
242228
} else {
243229
if (Utility.checkStorageAccessPermissions(context)) {
244230
Log.d(TAG, "Permission granted");
245231
dir();
246232
} else {
247-
Log.d(TAG, "Permission not granted");
233+
Log.d(TAG, "Permission not granted. You need to ask permission to user before accessing the storage and showing dialog.");
248234
}
249235
}
250236
}

sample/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ android {
77
applicationId "com.developer.filepicker.file"
88
minSdkVersion 19
99
targetSdkVersion 34
10-
versionCode 10
11-
versionName "9.0.2"
10+
versionCode 11
11+
versionName "9.1.3"
1212
}
1313
buildTypes {
1414
release {

sample/src/main/AndroidManifest.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO"/>
1010
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>
1111
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO"/>
12-
<!-- <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>-->
1312

1413
<application
1514
android:name="com.developer.filepicker.file.FilePickerApplication"

0 commit comments

Comments
 (0)