Skip to content
This repository was archived by the owner on Feb 11, 2022. It is now read-only.

Commit 464f6c4

Browse files
committed
Add test for multiple selection in StringExtras
1 parent 9133681 commit 464f6c4

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

sample/src/androidTestUitests/java/com/nononsenseapps/filepicker/sample/SelectMultipleFiles.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,23 @@ public void allowPermissions() {
4646
* Should not throw on Android 24
4747
*/
4848
@Test
49-
public void selectTwoFilesDoesNotThrow() {
49+
public void selectTwoFilesDoesNotThrowWithClipData() {
50+
NoNonsenseFilePicker.useClipData = true;
51+
52+
selectTwoFilesDoesNotThrow();
53+
}
54+
55+
/**
56+
* Should not throw on Android 24
57+
*/
58+
@Test
59+
public void selectTwoFilesDoesNotThrowWithStringExtras() {
60+
NoNonsenseFilePicker.useClipData = false;
61+
62+
selectTwoFilesDoesNotThrow();
63+
}
64+
65+
private void selectTwoFilesDoesNotThrow() {
5066
ViewInteraction radioButton = onView(
5167
allOf(withId(R.id.radioFile), withText("Select file"),
5268
withParent(withId(R.id.radioGroup)),

sample/src/main/java/com/nononsenseapps/filepicker/sample/NoNonsenseFilePicker.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242

4343
public class NoNonsenseFilePicker extends Activity {
4444

45+
// How to handle multiple return data
46+
public static boolean useClipData = true;
47+
4548
static final int CODE_SD = 0;
4649
static final int CODE_DB = 1;
4750
static final int CODE_FTP = 2;
@@ -226,7 +229,8 @@ protected void onActivityResult(int requestCode, int resultCode,
226229
// If we handled multiple files, we need to get the result differently
227230
if (data.getBooleanExtra(FilePickerActivity.EXTRA_ALLOW_MULTIPLE, false)) {
228231
// This is the typical style on Android 4.2 and above
229-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
232+
if (useClipData && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
233+
Log.i("SAMPLEAPP", "onActivityResult: Using ClipData");
230234
ClipData clip = data.getClipData();
231235
StringBuilder sb = new StringBuilder();
232236

@@ -245,6 +249,7 @@ protected void onActivityResult(int requestCode, int resultCode,
245249

246250
binding.text.setText(sb.toString());
247251
} else /* This style is available in all SDK versions */ {
252+
Log.i("SAMPLEAPP", "onActivityResult: Using StringExtras");
248253
ArrayList<String> paths = data.getStringArrayListExtra(
249254
FilePickerActivity.EXTRA_PATHS);
250255
StringBuilder sb = new StringBuilder();
@@ -255,7 +260,7 @@ protected void onActivityResult(int requestCode, int resultCode,
255260
sb.append("\n");
256261
}
257262
sb.append(CODE_SD == requestCode ?
258-
Utils.getFileForUriString(path).toString() :
263+
Utils.getFileForUri(Uri.parse(path)).toString() :
259264
path);
260265
}
261266
}

0 commit comments

Comments
 (0)