浏览代码

[modify]增加分享文件类型

zk 1 年之前
父节点
当前提交
68bf0b2108

+ 4 - 2
lib/utils/system_share_util.dart

@@ -13,7 +13,8 @@ class SystemShareUtil {
       if (!isInstalled) {
         throw SystemShareException('未安装微信');
       }
-      SystemShare.shareFile(filePath, wechatPackageName, '分享到微信');
+      SystemShare.shareFile(filePath, wechatPackageName, '分享到微信',
+          shareFileType: 'text/*');
     }
   }
 
@@ -25,7 +26,8 @@ class SystemShareUtil {
       if (!isInstalled) {
         throw SystemShareException('未安装QQ');
       }
-      SystemShare.shareFile(filePath, qqPackageName, '分享到QQ');
+      SystemShare.shareFile(filePath, qqPackageName, '分享到QQ',
+          shareFileType: 'text/*');
     }
   }
 

+ 2 - 1
plugin/system_share/android/src/main/java/com/atmob/system_share/SystemSharePlugin.java

@@ -73,6 +73,7 @@ public class SystemSharePlugin implements FlutterPlugin, MethodCallHandler {
             String filePath = call.argument("filePath");
             String packageName = call.argument("packageName");
             String shareTitle = call.argument("shareTitle");
+            String shareFileType = call.argument("shareFileType");
             if (TextUtils.isEmpty(filePath) || TextUtils.isEmpty(packageName)) {
                 result.error("-1", "SystemShare: filePath or packageName is empty or null", null);
                 return;
@@ -86,7 +87,7 @@ public class SystemSharePlugin implements FlutterPlugin, MethodCallHandler {
                 result.error("-1", "SystemShare: app not installed", null);
                 return;
             }
-            SystemShareUtil.shareFile(applicationContext, file, packageName, shareTitle);
+            SystemShareUtil.shareFile(applicationContext, file, packageName, shareTitle,shareFileType);
             result.success(null);
         } catch (Exception e) {
             e.printStackTrace();

+ 2 - 2
plugin/system_share/android/src/main/java/com/atmob/system_share/SystemShareUtil.java

@@ -22,9 +22,9 @@ public class SystemShareUtil {
         }
     }
 
-    static void shareFile(Context context, File file, String packageName, String shareTitle) {
+    static void shareFile(Context context, File file, String packageName, String shareTitle, String shareFileType) {
         Intent intent = new Intent(Intent.ACTION_SEND);
-        intent.setType("*/*");
+        intent.setType(shareFileType == null ? "*/*" : shareFileType);
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
             Uri fileUri = UriUtil.getFileUri(context, file);
             intent.putExtra(Intent.EXTRA_STREAM, fileUri);

+ 4 - 3
plugin/system_share/lib/system_share.dart

@@ -9,8 +9,9 @@ class SystemShare {
     return SystemSharePlatform.instance.isInstalled(packageName);
   }
 
-  static void shareFile(
-      String filePath, String packageName, String? shareTitle) {
-    SystemSharePlatform.instance.shareFile(filePath, packageName, shareTitle);
+  static void shareFile(String filePath, String packageName, String? shareTitle,
+      {String? shareFileType}) {
+    SystemSharePlatform.instance.shareFile(
+        filePath, packageName, shareTitle, shareFileType: shareFileType);
   }
 }

+ 3 - 1
plugin/system_share/lib/system_share_method_channel.dart

@@ -17,11 +17,13 @@ class MethodChannelSystemShare extends SystemSharePlatform {
   }
 
   @override
-  void shareFile(String filePath, String packageName, String? shareTitle) {
+  void shareFile(String filePath, String packageName, String? shareTitle,
+      {String? shareFileType}) {
     methodChannel.invokeMethod("shareFile", {
       "filePath": filePath,
       "packageName": packageName,
       "shareTitle": shareTitle,
+      "shareFileType": shareFileType,
     });
   }
 }

+ 2 - 2
plugin/system_share/lib/system_share_platform_interface.dart

@@ -29,8 +29,8 @@ abstract class SystemSharePlatform extends PlatformInterface {
     throw UnimplementedError('isInstalled() has not been implemented.');
   }
 
-  void shareFile(
-      String filePath, String packageName, String? shareTitle) async {
+  void shareFile(String filePath, String packageName, String? shareTitle,
+      {String? shareFileType}) async {
     throw UnimplementedError('shareFile() has not been implemented.');
   }
 }