Skip to content
This repository was archived by the owner on Jul 21, 2022. It is now read-only.
Open
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 @@ -2,6 +2,8 @@

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.util.Log;

Expand All @@ -10,6 +12,7 @@
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
Expand Down Expand Up @@ -83,7 +86,16 @@ private void file(Object arguments) {
shareIntent.putExtra(Intent.EXTRA_STREAM, contentUri);
// add optional text
if (!text.isEmpty()) shareIntent.putExtra(Intent.EXTRA_TEXT, text);
activeContext.startActivity(Intent.createChooser(shareIntent, title));


Intent chooser = Intent.createChooser(shareIntent, title);
List<ResolveInfo> resInfoList = activeContext.getPackageManager().queryIntentActivities(chooser, PackageManager.MATCH_DEFAULT_ONLY);

for (ResolveInfo resolveInfo : resInfoList) {
String packageName = resolveInfo.activityInfo.packageName;
activeContext.grantUriPermission(packageName, contentUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
activeContext.startActivity(chooser);
}

private void files(Object arguments) {
Expand Down Expand Up @@ -112,6 +124,15 @@ private void files(Object arguments) {
shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, contentUris);
// add optional text
if (!text.isEmpty()) shareIntent.putExtra(Intent.EXTRA_TEXT, text);
activeContext.startActivity(Intent.createChooser(shareIntent, title));
}

Intent chooser = Intent.createChooser(shareIntent, title);
List<ResolveInfo> resInfoList = activeContext.getPackageManager().queryIntentActivities(chooser, PackageManager.MATCH_DEFAULT_ONLY);

for (ResolveInfo resolveInfo : resInfoList) {
String packageName = resolveInfo.activityInfo.packageName;
for(Uri uri: contentUris){
activeContext.grantUriPermission(packageName, uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
}
activeContext.startActivity(chooser); }
}