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
b24c80ad
Commit
b24c80ad
authored
Jun 27, 2020
by
zhouteng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add extraText option for Android when sharing image or file
parent
dffcb800
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
21 deletions
+48
-21
android/src/main/java/com/zt/shareextend/ShareExtendPlugin.java
...d/src/main/java/com/zt/shareextend/ShareExtendPlugin.java
+6
-4
lib/share_extend.dart
lib/share_extend.dart
+42
-17
No files found.
android/src/main/java/com/zt/shareextend/ShareExtendPlugin.java
View file @
b24c80ad
...
@@ -34,6 +34,7 @@ public class ShareExtendPlugin implements MethodChannel.MethodCallHandler, Plugi
...
@@ -34,6 +34,7 @@ public class ShareExtendPlugin implements MethodChannel.MethodCallHandler, Plugi
private
String
type
;
private
String
type
;
private
String
sharePanelTitle
;
private
String
sharePanelTitle
;
private
String
subject
;
private
String
subject
;
private
String
extraText
;
public
static
void
registerWith
(
Registrar
registrar
)
{
public
static
void
registerWith
(
Registrar
registrar
)
{
MethodChannel
channel
=
new
MethodChannel
(
registrar
.
messenger
(),
CHANNEL
);
MethodChannel
channel
=
new
MethodChannel
(
registrar
.
messenger
(),
CHANNEL
);
...
@@ -58,14 +59,15 @@ public class ShareExtendPlugin implements MethodChannel.MethodCallHandler, Plugi
...
@@ -58,14 +59,15 @@ public class ShareExtendPlugin implements MethodChannel.MethodCallHandler, Plugi
type
=
call
.
argument
(
"type"
);
type
=
call
.
argument
(
"type"
);
sharePanelTitle
=
call
.
argument
(
"sharePanelTitle"
);
sharePanelTitle
=
call
.
argument
(
"sharePanelTitle"
);
subject
=
call
.
argument
(
"subject"
);
subject
=
call
.
argument
(
"subject"
);
share
(
list
,
type
,
sharePanelTitle
,
subject
);
extraText
=
call
.
argument
(
"extraText"
);
share
(
list
,
type
,
sharePanelTitle
,
subject
,
extraText
);
result
.
success
(
null
);
result
.
success
(
null
);
}
else
{
}
else
{
result
.
notImplemented
();
result
.
notImplemented
();
}
}
}
}
private
void
share
(
List
<
String
>
list
,
String
type
,
String
sharePanelTitle
,
String
subject
)
{
private
void
share
(
List
<
String
>
list
,
String
type
,
String
sharePanelTitle
,
String
subject
,
String
extraText
)
{
ArrayList
<
Uri
>
uriList
=
new
ArrayList
<>();;
ArrayList
<
Uri
>
uriList
=
new
ArrayList
<>();;
if
(
list
==
null
||
list
.
isEmpty
())
{
if
(
list
==
null
||
list
.
isEmpty
())
{
...
@@ -86,7 +88,7 @@ public class ShareExtendPlugin implements MethodChannel.MethodCallHandler, Plugi
...
@@ -86,7 +88,7 @@ public class ShareExtendPlugin implements MethodChannel.MethodCallHandler, Plugi
return
;
return
;
}
}
}
}
shareIntent
.
putExtra
(
Intent
.
EXTRA_TEXT
,
extraText
);
for
(
String
path
:
list
)
{
for
(
String
path
:
list
)
{
File
f
=
new
File
(
path
);
File
f
=
new
File
(
path
);
Uri
uri
=
ShareUtils
.
getUriForFile
(
getContext
(),
f
);
Uri
uri
=
ShareUtils
.
getUriForFile
(
getContext
(),
f
);
...
@@ -139,7 +141,7 @@ public class ShareExtendPlugin implements MethodChannel.MethodCallHandler, Plugi
...
@@ -139,7 +141,7 @@ public class ShareExtendPlugin implements MethodChannel.MethodCallHandler, Plugi
@Override
@Override
public
boolean
onRequestPermissionsResult
(
int
requestCode
,
String
[]
perms
,
int
[]
grantResults
)
{
public
boolean
onRequestPermissionsResult
(
int
requestCode
,
String
[]
perms
,
int
[]
grantResults
)
{
if
(
requestCode
==
CODE_ASK_PERMISSION
&&
grantResults
.
length
>
0
&&
grantResults
[
0
]
==
PackageManager
.
PERMISSION_GRANTED
)
{
if
(
requestCode
==
CODE_ASK_PERMISSION
&&
grantResults
.
length
>
0
&&
grantResults
[
0
]
==
PackageManager
.
PERMISSION_GRANTED
)
{
share
(
list
,
type
,
sharePanelTitle
,
subject
);
share
(
list
,
type
,
sharePanelTitle
,
subject
,
extraText
);
}
}
return
false
;
return
false
;
}
}
...
...
lib/share_extend.dart
View file @
b24c80ad
...
@@ -14,27 +14,27 @@ class ShareExtend {
...
@@ -14,27 +14,27 @@ class ShareExtend {
static
const
MethodChannel
_channel
=
static
const
MethodChannel
_channel
=
const
MethodChannel
(
'com.zt.shareextend/share_extend'
);
const
MethodChannel
(
'com.zt.shareextend/share_extend'
);
///
/// method to share with system ui
/// [sharePositionOrigin] only supports ios
/// It uses the ACTION_SEND Intent on Android and UIActivityViewController
/// on iOS.
/// [list] can be text or path list
/// [type] "text", "image" ,"file"
/// [sharePositionOrigin] only supports iPad os
/// [sharePanelTitle] only supports android (some devices may not support)
/// [subject] Intent.EXTRA_SUBJECT on Android and "subject" on iOS.
/// [extraText] only supports android for Intent.EXTRA_TEXT when sharing image or file.
///
///
static
Future
<
void
>
shareMultiple
(
List
<
String
>
list
,
String
type
,
static
Future
<
void
>
shareMultiple
(
List
<
String
>
list
,
String
type
,
{
Rect
sharePositionOrigin
,
String
sharePanelTitle
,
String
subject
})
{
{
Rect
sharePositionOrigin
,
String
sharePanelTitle
,
String
subject
=
""
,
String
extraText
=
""
})
{
assert
(
list
!=
null
&&
list
.
isNotEmpty
);
assert
(
list
!=
null
&&
list
.
isNotEmpty
);
return
_shareInner
(
list
,
type
,
return
_shareInner
(
list
,
type
,
sharePositionOrigin:
sharePositionOrigin
,
sharePositionOrigin:
sharePositionOrigin
,
subject:
subject
,
subject:
subject
,
sharePanelTitle:
sharePanelTitle
);
}
static
Future
<
void
>
share
(
String
text
,
String
type
,
{
Rect
sharePositionOrigin
,
String
sharePanelTitle
,
String
subject
=
""
})
{
assert
(
text
!=
null
);
assert
(
text
.
isNotEmpty
);
List
<
String
>
list
=
[
text
];
return
_shareInner
(
list
,
type
,
sharePositionOrigin:
sharePositionOrigin
,
sharePanelTitle:
sharePanelTitle
,
sharePanelTitle:
sharePanelTitle
,
subject:
subjec
t
);
extraText:
extraTex
t
);
}
}
/// method to share with system ui
/// method to share with system ui
...
@@ -42,16 +42,41 @@ class ShareExtend {
...
@@ -42,16 +42,41 @@ class ShareExtend {
/// on iOS.
/// on iOS.
/// [list] can be text or path list
/// [list] can be text or path list
/// [type] "text", "image" ,"file"
/// [type] "text", "image" ,"file"
/// [sharePositionOrigin] only supports ios
/// [sharePositionOrigin] only supports iPad os
/// [sharePanelTitle] only supports android (some devices may not support)
/// [subject] Intent.EXTRA_SUBJECT on Android and "subject" on iOS.
/// [extraText] only supports android for Intent.EXTRA_TEXT when sharing image or file.
///
///
static
Future
<
void
>
share
(
String
text
,
String
type
,
{
Rect
sharePositionOrigin
,
String
sharePanelTitle
,
String
subject
=
""
,
String
extraText
=
""
})
{
assert
(
text
!=
null
);
assert
(
text
.
isNotEmpty
);
List
<
String
>
list
=
[
text
];
return
_shareInner
(
list
,
type
,
sharePositionOrigin:
sharePositionOrigin
,
sharePanelTitle:
sharePanelTitle
,
subject:
subject
,
extraText:
extraText
,
);
}
static
Future
<
void
>
_shareInner
(
List
<
String
>
list
,
String
type
,
static
Future
<
void
>
_shareInner
(
List
<
String
>
list
,
String
type
,
{
Rect
sharePositionOrigin
,
String
sharePanelTitle
,
String
subject
})
{
{
Rect
sharePositionOrigin
,
String
sharePanelTitle
,
String
subject
,
String
extraText
})
{
assert
(
list
!=
null
&&
list
.
isNotEmpty
);
assert
(
list
!=
null
&&
list
.
isNotEmpty
);
final
Map
<
String
,
dynamic
>
params
=
<
String
,
dynamic
>{
final
Map
<
String
,
dynamic
>
params
=
<
String
,
dynamic
>{
'list'
:
list
,
'list'
:
list
,
'type'
:
type
,
'type'
:
type
,
'sharePanelTitle'
:
sharePanelTitle
,
'sharePanelTitle'
:
sharePanelTitle
,
'subject'
:
subject
'subject'
:
subject
,
'extraText'
:
extraText
};
};
if
(
sharePositionOrigin
!=
null
)
{
if
(
sharePositionOrigin
!=
null
)
{
params
[
'originX'
]
=
sharePositionOrigin
.
left
;
params
[
'originX'
]
=
sharePositionOrigin
.
left
;
...
...
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