Commit b24c80ad authored by zhouteng's avatar zhouteng

Add extraText option for Android when sharing image or file

parent dffcb800
...@@ -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;
} }
......
...@@ -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: subject); extraText: extraText);
} }
/// 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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment