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
5bc96ef8
Commit
5bc96ef8
authored
Mar 29, 2019
by
zhouteng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复分享app沙盒文件可能不成功的bug
parent
7768b83a
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
32 additions
and
15 deletions
+32
-15
CHANGELOG.md
CHANGELOG.md
+4
-0
README.md
README.md
+1
-1
android/src/main/AndroidManifest.xml
android/src/main/AndroidManifest.xml
+1
-0
android/src/main/java/com/zt/shareextend/ShareExtendPlugin.java
...d/src/main/java/com/zt/shareextend/ShareExtendPlugin.java
+9
-11
android/src/main/java/com/zt/shareextend/ShareUtils.java
android/src/main/java/com/zt/shareextend/ShareUtils.java
+16
-2
pubspec.yaml
pubspec.yaml
+1
-1
No files found.
CHANGELOG.md
View file @
5bc96ef8
## 1.0.6
*
修复了android端分享应用沙盒内文件可能出错的bug
*
优化了android端分享时的权限请求逻辑
## 1.0.5
*
Fix bugs when sharing videos to some apps like WeChat.
...
...
README.md
View file @
5bc96ef8
...
...
@@ -5,7 +5,7 @@
```
dependencies:
share_extend: "^1.0.
5
"
share_extend: "^1.0.
6
"
```
## 导入
```
...
...
android/src/main/AndroidManifest.xml
View file @
5bc96ef8
...
...
@@ -2,6 +2,7 @@
package=
"com.zt.shareextend"
>
<uses-permission
android:name=
"android.permission.READ_EXTERNAL_STORAGE"
/>
<uses-permission
android:name=
"android.permission.WRITE_EXTERNAL_STORAGE"
/>
<application>
...
...
android/src/main/java/com/zt/shareextend/ShareExtendPlugin.java
View file @
5bc96ef8
...
...
@@ -4,7 +4,7 @@ import android.Manifest;
import
android.content.Intent
;
import
android.content.pm.PackageManager
;
import
android.net.Uri
;
import
android.os.
Environment
;
import
android.os.
Build
;
import
java.io.File
;
import
java.util.Map
;
...
...
@@ -69,16 +69,19 @@ public class ShareExtendPlugin implements MethodChannel.MethodCallHandler, Plugi
shareIntent
.
putExtra
(
Intent
.
EXTRA_TEXT
,
text
);
shareIntent
.
setType
(
"text/plain"
);
}
else
{
File
f
=
new
File
(
text
);
if
(!
f
.
exists
())
{
throw
new
IllegalArgumentException
(
"file not exists"
);
}
if
(
isPathInExternalStorage
(
text
))
{
if
(
ShareUtils
.
shouldRequestPermission
(
text
))
{
if
(!
checkPermisson
())
{
requestPermission
();
return
;
}
}
File
f
=
new
File
(
text
);
Uri
uri
=
ShareUtils
.
getUriForFile
(
mRegistrar
.
context
(),
f
);
Uri
uri
=
ShareUtils
.
getUriForFile
(
mRegistrar
.
context
(),
f
,
type
);
if
(
"image"
.
equals
(
type
))
{
shareIntent
.
setType
(
"image/*"
);
...
...
@@ -99,13 +102,8 @@ public class ShareExtendPlugin implements MethodChannel.MethodCallHandler, Plugi
}
}
private
boolean
isPathInExternalStorage
(
String
path
)
{
File
storagePath
=
Environment
.
getExternalStorageDirectory
();
return
path
.
startsWith
(
storagePath
.
getAbsolutePath
());
}
private
boolean
checkPermisson
()
{
if
(
ContextCompat
.
checkSelfPermission
(
mRegistrar
.
context
(),
Manifest
.
permission
.
READ
_EXTERNAL_STORAGE
)
if
(
ContextCompat
.
checkSelfPermission
(
mRegistrar
.
context
(),
Manifest
.
permission
.
WRITE
_EXTERNAL_STORAGE
)
==
PackageManager
.
PERMISSION_GRANTED
)
{
return
true
;
}
...
...
@@ -113,7 +111,7 @@ public class ShareExtendPlugin implements MethodChannel.MethodCallHandler, Plugi
}
private
void
requestPermission
()
{
ActivityCompat
.
requestPermissions
(
mRegistrar
.
activity
(),
new
String
[]{
Manifest
.
permission
.
READ
_EXTERNAL_STORAGE
},
CODE_ASK_PERMISSION
);
ActivityCompat
.
requestPermissions
(
mRegistrar
.
activity
(),
new
String
[]{
Manifest
.
permission
.
WRITE
_EXTERNAL_STORAGE
},
CODE_ASK_PERMISSION
);
}
@Override
...
...
android/src/main/java/com/zt/shareextend/ShareUtils.java
View file @
5bc96ef8
...
...
@@ -6,6 +6,7 @@ import android.content.Context;
import
android.database.Cursor
;
import
android.net.Uri
;
import
android.os.Build
;
import
android.os.Environment
;
import
android.provider.MediaStore
;
import
android.text.TextUtils
;
...
...
@@ -16,7 +17,7 @@ import androidx.core.content.FileProvider;
public
class
ShareUtils
{
/// get the uri for file
public
static
Uri
getUriForFile
(
Context
context
,
File
file
)
{
public
static
Uri
getUriForFile
(
Context
context
,
File
file
,
String
type
)
{
String
authorities
=
context
.
getPackageName
()
+
".fileprovider"
;
...
...
@@ -26,7 +27,11 @@ public class ShareUtils {
uri
=
Uri
.
fromFile
(
file
);
}
else
{
// 使用 FileProvider 会在某些 app 下不支持(在使用FileProvider 方式情况下QQ不能支持图片、视频分享,微信不支持视频分享)
uri
=
FileProvider
.
getUriForFile
(
context
,
authorities
,
file
);
uri
=
FileProvider
.
getUriForFile
(
context
,
authorities
,
file
);
if
(!
isPathInExternalStorage
(
file
.
getAbsolutePath
())
||
"file"
.
equals
(
type
))
{
return
uri
;
}
ContentResolver
cR
=
context
.
getContentResolver
();
if
(
uri
!=
null
&&
!
TextUtils
.
isEmpty
(
uri
.
toString
()))
{
...
...
@@ -46,6 +51,15 @@ public class ShareUtils {
return
uri
;
}
public
static
boolean
shouldRequestPermission
(
String
path
)
{
return
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
M
&&
isPathInExternalStorage
(
path
);
}
private
static
boolean
isPathInExternalStorage
(
String
path
)
{
File
storagePath
=
Environment
.
getExternalStorageDirectory
();
return
path
.
startsWith
(
storagePath
.
getAbsolutePath
());
}
/**
* Gets the content:// URI from the given corresponding path to a file
*
...
...
pubspec.yaml
View file @
5bc96ef8
name
:
share_extend
description
:
A flutter plugin to share text, image, file with system ui. It is compatible with both andorid and ios.
version
:
1.0.
5
version
:
1.0.
6
author
:
zhouteng <qfszyq@gmail.com>
homepage
:
https://github.com/zhouteng0217/ShareExtend
...
...
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