Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
ShareExtend
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
李增强
ShareExtend
Commits
483292ab
Commit
483292ab
authored
Apr 17, 2020
by
zhouteng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add grant uri permission on Android
parent
2f2ced98
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
10 deletions
+22
-10
android/src/main/java/com/zt/shareextend/ShareExtendPlugin.java
...d/src/main/java/com/zt/shareextend/ShareExtendPlugin.java
+11
-10
android/src/main/java/com/zt/shareextend/ShareUtils.java
android/src/main/java/com/zt/shareextend/ShareUtils.java
+11
-0
No files found.
android/src/main/java/com/zt/shareextend/ShareExtendPlugin.java
View file @
483292ab
package
com.zt.shareextend
;
import
android.Manifest
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.content.pm.PackageManager
;
import
android.content.pm.ResolveInfo
;
...
...
@@ -72,7 +73,6 @@ public class ShareExtendPlugin implements MethodChannel.MethodCallHandler, Plugi
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
));
...
...
@@ -85,9 +85,10 @@ public class ShareExtendPlugin implements MethodChannel.MethodCallHandler, Plugi
}
}
ArrayList
<
Uri
>
uriList
=
new
ArrayList
<>();
for
(
String
path
:
list
)
{
File
f
=
new
File
(
path
);
Uri
uri
=
ShareUtils
.
getUriForFile
(
mRegistrar
.
activity
(),
f
);
Uri
uri
=
ShareUtils
.
getUriForFile
(
getContext
(),
f
);
uriList
.
add
(
uri
);
}
...
...
@@ -105,18 +106,18 @@ public class ShareExtendPlugin implements MethodChannel.MethodCallHandler, Plugi
shareIntent
.
setAction
(
Intent
.
ACTION_SEND_MULTIPLE
);
shareIntent
.
putParcelableArrayListExtra
(
Intent
.
EXTRA_STREAM
,
uriList
);
}
ShareUtils
.
grantUriPermission
(
getContext
(),
uriList
,
shareIntent
);
}
startChooserActivity
(
uriList
.
get
(
0
),
shareIntent
,
sharePanelTitle
);
startChooserActivity
(
shareIntent
,
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
);
private
Context
getContext
()
{
return
mRegistrar
.
activity
()
!=
null
?
mRegistrar
.
activity
()
:
mRegistrar
.
context
();
}
private
void
startChooserActivity
(
Intent
shareIntent
,
String
sharePanelTitle
)
{
Intent
chooserIntent
=
Intent
.
createChooser
(
shareIntent
,
sharePanelTitle
);
if
(
mRegistrar
.
activity
()
!=
null
)
{
mRegistrar
.
activity
().
startActivity
(
chooserIntent
);
}
else
{
chooserIntent
.
addFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
);
...
...
android/src/main/java/com/zt/shareextend/ShareUtils.java
View file @
483292ab
package
com.zt.shareextend
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.content.pm.PackageManager
;
import
android.content.pm.ResolveInfo
;
import
android.net.Uri
;
import
android.os.Build
;
import
android.os.Environment
;
...
...
@@ -26,6 +29,14 @@ class ShareUtils {
return
uri
;
}
static
void
grantUriPermission
(
Context
context
,
List
<
Uri
>
uriList
,
Intent
intent
)
{
for
(
Uri
uri
:
uriList
)
{
List
<
ResolveInfo
>
resolveInfos
=
context
.
getPackageManager
().
queryIntentActivities
(
intent
,
PackageManager
.
MATCH_DEFAULT_ONLY
);
for
(
ResolveInfo
resolveInfo
:
resolveInfos
)
{
context
.
grantUriPermission
(
resolveInfo
.
activityInfo
.
packageName
,
uri
,
Intent
.
FLAG_GRANT_READ_URI_PERMISSION
|
Intent
.
FLAG_GRANT_WRITE_URI_PERMISSION
);
}
}
}
static
boolean
shouldRequestPermission
(
List
<
String
>
pathList
)
{
for
(
String
path
:
pathList
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment