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

Add static helper method #121

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@
package com.nononsenseapps.filepicker;

import android.annotation.SuppressLint;
import android.content.ClipData;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.support.annotation.Nullable;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

@SuppressLint("Registered")
public class FilePickerActivity extends AbstractFilePickerActivity<File> {
Expand All @@ -30,4 +36,28 @@ protected AbstractFilePickerFragment<File> getFragment(
mode, allowMultiple, allowCreateDir, allowExistingFile, singleClick);
return fragment;
}


@SuppressWarnings("unused")
public static List<Uri> getActivityResult(Intent data) {
List<Uri> result = new ArrayList<>();
if (data.getBooleanExtra(FilePickerActivity.EXTRA_ALLOW_MULTIPLE, false)) {
ClipData clip;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && (clip = data.getClipData()) != null) {
for (int i = 0; i < clip.getItemCount(); i++) {
result.add(clip.getItemAt(i).getUri());
}
} else {
List<String> paths = data.getStringArrayListExtra(FilePickerActivity.EXTRA_PATHS);
if (paths != null) {
for (String path : paths) {
result.add(Uri.parse(path));
}
}
}
} else {
result.add(data.getData());
}
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.app.Activity;
import android.content.ClipData;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
Expand Down Expand Up @@ -241,37 +242,11 @@ protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
if ((CODE_SD == requestCode || CODE_DB == requestCode || CODE_FTP == requestCode) &&
resultCode == Activity.RESULT_OK) {
if (data.getBooleanExtra(FilePickerActivity.EXTRA_ALLOW_MULTIPLE,
false)) {

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
ClipData clip = data.getClipData();
StringBuilder sb = new StringBuilder();

if (clip != null) {
for (int i = 0; i < clip.getItemCount(); i++) {
sb.append(clip.getItemAt(i).getUri().toString());
sb.append("\n");
}
}

textView.setText(sb.toString());
} else {
ArrayList<String> paths = data.getStringArrayListExtra(
FilePickerActivity.EXTRA_PATHS);
StringBuilder sb = new StringBuilder();

if (paths != null) {
for (String path : paths) {
sb.append(path);
sb.append("\n");
}
}
textView.setText(sb.toString());
}
} else {
textView.setText(data.getData().toString());
StringBuilder sb = new StringBuilder();
for (Uri uri : FilePickerActivity.getActivityResult(data)){
sb.append(uri).append('\n');
}
textView.setText(sb.toString());
}
}

Expand Down