Skip to content

Commit

Permalink
Merge pull request #28 from JEuler/fix-content-provider
Browse files Browse the repository at this point in the history
Fix content provider
  • Loading branch information
zhouteng0217 authored Apr 17, 2020
2 parents 6435b31 + d050e97 commit 2f2ced9
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions android/src/main/java/com/zt/shareextend/ShareExtendPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;

import java.io.File;
Expand Down Expand Up @@ -71,6 +72,7 @@ private void share(List<String> list, String type, String sharePanelTitle, Strin
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
shareIntent.putExtra(Intent.EXTRA_SUBJECT, subject);

ArrayList<Uri> uriList = new ArrayList<>();
if ("text".equals(type)) {
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, list.get(0));
Expand All @@ -83,7 +85,6 @@ private void share(List<String> list, String type, String sharePanelTitle, Strin
}
}

ArrayList<Uri> uriList = new ArrayList<>();
for (String path : list) {
File f = new File(path);
Uri uri = ShareUtils.getUriForFile(mRegistrar.activity(), f);
Expand All @@ -105,12 +106,17 @@ private void share(List<String> list, String type, String sharePanelTitle, Strin
shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uriList);
}
}
startChooserActivity(shareIntent, sharePanelTitle);
startChooserActivity(uriList.get(0), shareIntent, sharePanelTitle);
}

private void startChooserActivity(Intent shareIntent,String sharePanelTitle) {
private void startChooserActivity(Uri uri, Intent shareIntent,String sharePanelTitle) {
Intent chooserIntent = Intent.createChooser(shareIntent, sharePanelTitle /* dialog subject optional */);
if (mRegistrar.activity() != null) {
List<ResolveInfo> resInfoList = mRegistrar.activity().getPackageManager().queryIntentActivities(chooserIntent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolveInfo : resInfoList) {
String packageName = resolveInfo.activityInfo.packageName;
mRegistrar.activity().grantUriPermission(packageName, uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
mRegistrar.activity().startActivity(chooserIntent);
} else {
chooserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Expand Down

0 comments on commit 2f2ced9

Please sign in to comment.