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
private String type;
private String sharePanelTitle;
private String subject;
private String extraText;
public static void registerWith(Registrar registrar) {
MethodChannel channel = new MethodChannel(registrar.messenger(), CHANNEL);
......@@ -58,14 +59,15 @@ public class ShareExtendPlugin implements MethodChannel.MethodCallHandler, Plugi
type = call.argument("type");
sharePanelTitle = call.argument("sharePanelTitle");
subject = call.argument("subject");
share(list, type, sharePanelTitle, subject);
extraText = call.argument("extraText");
share(list, type, sharePanelTitle, subject, extraText);
result.success(null);
} else {
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<>();;
if (list == null || list.isEmpty()) {
......@@ -86,7 +88,7 @@ public class ShareExtendPlugin implements MethodChannel.MethodCallHandler, Plugi
return;
}
}
shareIntent.putExtra(Intent.EXTRA_TEXT, extraText);
for (String path : list) {
File f = new File(path);
Uri uri = ShareUtils.getUriForFile(getContext(), f);
......@@ -139,7 +141,7 @@ public class ShareExtendPlugin implements MethodChannel.MethodCallHandler, Plugi
@Override
public boolean onRequestPermissionsResult(int requestCode, String[] perms, int[] grantResults) {
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;
}
......
......@@ -14,44 +14,69 @@ class ShareExtend {
static const MethodChannel _channel =
const MethodChannel('com.zt.shareextend/share_extend');
///
/// [sharePositionOrigin] only supports ios
/// method to share with system ui
/// 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,
{Rect sharePositionOrigin, String sharePanelTitle, String subject}) {
{Rect sharePositionOrigin,
String sharePanelTitle,
String subject = "",
String extraText = ""}) {
assert(list != null && list.isNotEmpty);
return _shareInner(list, type,
sharePositionOrigin: sharePositionOrigin,
subject: subject,
sharePanelTitle: sharePanelTitle);
sharePanelTitle: sharePanelTitle,
extraText: extraText);
}
/// method to share with system ui
/// 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> share(String text, String type,
{Rect sharePositionOrigin, String sharePanelTitle, String subject = ""}) {
{Rect sharePositionOrigin,
String sharePanelTitle,
String subject = "",
String extraText = ""}) {
assert(text != null);
assert(text.isNotEmpty);
List<String> list = [text];
return _shareInner(list, type,
return _shareInner(
list,
type,
sharePositionOrigin: sharePositionOrigin,
sharePanelTitle: sharePanelTitle,
subject: subject);
subject: subject,
extraText: extraText,
);
}
/// method to share with system ui
/// 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 ios
///
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);
final Map<String, dynamic> params = <String, dynamic>{
'list': list,
'type': type,
'sharePanelTitle': sharePanelTitle,
'subject': subject
'subject': subject,
'extraText': extraText
};
if (sharePositionOrigin != null) {
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