Skip to content

Commit 89f7647

Browse files
committed
fix clipdata
1 parent f876ead commit 89f7647

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

PowerFileExplorer/src/main/AndroidManifest.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
44
package="net.gnu.explorer"
55
android:versionCode="64"
6-
android:versionName="1.0.13"
6+
android:versionName="1.0.14"
77
>
88

99
<!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle
@@ -103,6 +103,7 @@
103103
<action android:name="android.intent.action.VIEW" />
104104
<action android:name="android.intent.action.EDIT" />
105105
<action android:name="android.intent.action.PICK" />
106+
<action android:name="android.intent.action.MULTIPLE_PICK" />
106107
<action android:name="org.openintents.action.PICK_FILE"/>
107108
<action android:name="org.openintents.action.PICK_DIRECTORY"/>
108109
<action android:name="android.intent.action.SEND" />
@@ -122,6 +123,7 @@
122123
<action android:name="android.intent.action.VIEW" />
123124
<action android:name="android.intent.action.EDIT" />
124125
<action android:name="android.intent.action.PICK" />
126+
<action android:name="android.intent.action.MULTIPLE_PICK" />
125127
<action android:name="org.openintents.action.PICK_FILE"/>
126128
<action android:name="org.openintents.action.PICK_DIRECTORY"/>
127129
<action android:name="android.intent.action.SEND" />
@@ -153,6 +155,7 @@
153155
<action android:name="android.intent.action.VIEW" />
154156
<action android:name="android.intent.action.EDIT" />
155157
<action android:name="android.intent.action.PICK" />
158+
<action android:name="android.intent.action.MULTIPLE_PICK" />
156159
<action android:name="org.openintents.action.PICK_FILE"/>
157160
<action android:name="org.openintents.action.PICK_DIRECTORY"/>
158161
<action android:name="android.intent.action.SEND" />

PowerFileExplorer/src/main/java/net/gnu/explorer/ExplorerActivity.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@
133133
import android.widget.ArrayAdapter;
134134
import net.gnu.common.*;
135135
import android.support.v4.content.FileProvider;
136+
import android.content.*;
136137

137138

138139
public class ExplorerActivity extends StorageCheckActivity implements OnRequestPermissionsResultCallback,
@@ -531,7 +532,9 @@ public void onCreate(final Bundle savedInstanceState) {
531532
suffix = intent.getStringExtra(Constants.EXTRA_FILTER_FILETYPE);
532533
suffix = (suffix == null) ? "" : suffix.trim();
533534

534-
multiFiles = intent.getBooleanExtra(Constants.EXTRA_MULTI_SELECT, true);
535+
multiFiles = intent.getBooleanExtra(Constants.EXTRA_MULTI_SELECT, true)
536+
&& intent.getBooleanExtra(Intent.EXTRA_ALLOW_MULTIPLE, true)
537+
&& intent.getBooleanExtra("android.intent.action.MULTIPLE_PICK", true);
535538

536539
mimes = intent.getStringExtra(Constants.EXTRA_FILTER_MIMETYPE);
537540
//mimes = (mimes == null) ? "" : mimes;
@@ -546,13 +549,13 @@ public void onCreate(final Bundle savedInstanceState) {
546549
if (suffix.length() == 0) {
547550
suffix = ".*";
548551
}
549-
} else if (Intent.ACTION_GET_CONTENT.equals(action)) {
552+
} else if (Intent.ACTION_GET_CONTENT.equals(action) && !intent.getBooleanExtra(Intent.EXTRA_ALLOW_MULTIPLE, true)) {
550553
multiFiles = false;
551554
if (suffix.length() == 0) {
552555
suffix = ".*";
553556
}
554557
} else {
555-
suffix = "*";
558+
suffix = ".*";
556559
}
557560
previousSelectedStr = intent.getStringArrayExtra(Constants.PREVIOUS_SELECTED_FILES);
558561
Log.d(TAG, "previousSelectedStr " + Util.arrayToString(previousSelectedStr, true, "\n"));
@@ -2891,9 +2894,22 @@ public void ok(View view) {
28912894
}
28922895
intent.putStringArrayListExtra(Constants.PREVIOUS_SELECTED_FILES, fileArr);
28932896
intent.putExtra(Constants.EXTRA_MULTI_SELECT, multiFiles);
2894-
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
2897+
final int size = fileArr.size();
2898+
if (size == 1) {
2899+
intent.setData(FileProvider.getUriForFile(this, "net.gnu.explorer.fileprovider", new File(fileArr.get(0))));
2900+
} else if (size > 1) {
2901+
final ClipData clipData = ClipData.newRawUri(
2902+
"", FileProvider.getUriForFile(this, "net.gnu.explorer.fileprovider", new File(fileArr.get(0))));
2903+
for (int i = 1; i < size; i ++) {
2904+
clipData.addItem(new ClipData.Item(FileProvider.getUriForFile(this, "net.gnu.explorer.fileprovider", new File(fileArr.get(i)))));
2905+
}
2906+
intent.setClipData(clipData);
2907+
}
2908+
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION
2909+
| Intent.FLAG_GRANT_WRITE_URI_PERMISSION
2910+
| Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
28952911
setResult(RESULT_OK, intent);
2896-
Log.d(TAG, "ok " + getIntent() + ", " + getIntent().getExtras());
2912+
Log.i(TAG, "ok " + intent + ", " + intent.getExtras());
28972913
this.finish();
28982914
}
28992915

0 commit comments

Comments
 (0)