diff --git a/android/src/main/java/zhuoyuan/li/fluttershareme/FlutterShareMePlugin.java b/android/src/main/java/zhuoyuan/li/fluttershareme/FlutterShareMePlugin.java index ac882f2..0680272 100644 --- a/android/src/main/java/zhuoyuan/li/fluttershareme/FlutterShareMePlugin.java +++ b/android/src/main/java/zhuoyuan/li/fluttershareme/FlutterShareMePlugin.java @@ -5,6 +5,7 @@ import android.content.Intent; import android.net.Uri; import android.text.TextUtils; +import android.util.Log; import androidx.annotation.NonNull; import androidx.core.content.FileProvider; @@ -18,8 +19,10 @@ import com.twitter.sdk.android.tweetcomposer.TweetComposer; import java.io.File; +import java.io.UnsupportedEncodingException; import java.net.MalformedURLException; import java.net.URL; +import java.net.URLEncoder; import io.flutter.embedding.engine.plugins.FlutterPlugin; import io.flutter.embedding.engine.plugins.activity.ActivityAware; @@ -36,6 +39,14 @@ */ public class FlutterShareMePlugin implements MethodCallHandler, FlutterPlugin, ActivityAware { + final private static String _methodWhatsApp = "whatsapp_share"; + final private static String _methodWhatsAppPersonal = "whatsapp_personal"; + final private static String _methodWhatsAppBusiness = "whatsapp_business_share"; + final private static String _methodFaceBook = "facebook_share"; + final private static String _methodTwitter = "twitter_share"; + final private static String _methodSystemShare = "system_share"; + + private Activity activity; private static CallbackManager callbackManager; private MethodChannel methodChannel; @@ -77,27 +88,32 @@ private void onAttachedToEngine(BinaryMessenger messenger) { public void onMethodCall(MethodCall call, @NonNull Result result) { String url, msg; switch (call.method) { - case "shareFacebook": + case _methodFaceBook: url = call.argument("url"); msg = call.argument("msg"); shareToFacebook(url, msg, result); break; - case "shareTwitter": + case _methodTwitter: url = call.argument("url"); msg = call.argument("msg"); shareToTwitter(url, msg, result); break; - case "shareWhatsApp": + case _methodWhatsApp: msg = call.argument("msg"); url = call.argument("url"); shareWhatsApp(url, msg, result, false); break; - case "shareWhatsApp4Biz": + case _methodWhatsAppBusiness: msg = call.argument("msg"); url = call.argument("url"); shareWhatsApp(url, msg, result, true); break; - case "system": + case _methodWhatsAppPersonal: + msg = call.argument("msg"); + String phoneNumber = call.argument("phoneNumber"); + shareWhatsAppPersonal(msg,phoneNumber , result); + break; + case _methodSystemShare: msg = call.argument("msg"); shareSystem(result, msg); break; @@ -132,6 +148,7 @@ private void shareSystem(Result result, String msg) { * @param msg String * @param result Result */ + private void shareToTwitter(String url, String msg, Result result) { try { TweetComposer.Builder builder = new TweetComposer.Builder(activity) @@ -214,6 +231,27 @@ private void shareWhatsApp(String url, String msg, Result result, boolean shareT } } + /** + * share whatsapp message to personal number + * @param msg String + * @param phoneNumber String with country code + * @param result + */ + private void shareWhatsAppPersonal(String msg, String phoneNumber, Result result){ + String url = null; + try { + url = "https://api.whatsapp.com/send?phone="+phoneNumber +"&text=" + URLEncoder.encode(msg, "UTF-8"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + + Intent i = new Intent(Intent.ACTION_VIEW); + i.setPackage("com.whatsapp"); + i.setData(Uri.parse(url)); + activity.startActivity(i); + result.success("success"); + } + @Override public void onAttachedToActivity(ActivityPluginBinding binding) { activity = binding.getActivity(); diff --git a/example/.flutter-plugins-dependencies b/example/.flutter-plugins-dependencies index 8b50db0..3f56cc4 100644 --- a/example/.flutter-plugins-dependencies +++ b/example/.flutter-plugins-dependencies @@ -1 +1 @@ -{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"flutter_share_me","path":"/Users/jigafumakiya/Documents/Jigar/plugin/open_flutter_share_me/flutter_share_me/","dependencies":[]},{"name":"image_picker","path":"/Users/jigafumakiya/Documents/FlutterSDK/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker-0.8.3+2/","dependencies":[]},{"name":"path_provider","path":"/Users/jigafumakiya/Documents/FlutterSDK/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-2.0.2/","dependencies":[]}],"android":[{"name":"flutter_plugin_android_lifecycle","path":"/Users/jigafumakiya/Documents/FlutterSDK/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_plugin_android_lifecycle-2.0.2/","dependencies":[]},{"name":"flutter_share_me","path":"/Users/jigafumakiya/Documents/Jigar/plugin/open_flutter_share_me/flutter_share_me/","dependencies":[]},{"name":"image_picker","path":"/Users/jigafumakiya/Documents/FlutterSDK/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker-0.8.3+2/","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"path_provider","path":"/Users/jigafumakiya/Documents/FlutterSDK/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-2.0.2/","dependencies":[]}],"macos":[{"name":"path_provider_macos","path":"/Users/jigafumakiya/Documents/FlutterSDK/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_macos-2.0.2/","dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"/Users/jigafumakiya/Documents/FlutterSDK/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_linux-2.0.2/","dependencies":[]}],"windows":[{"name":"path_provider_windows","path":"/Users/jigafumakiya/Documents/FlutterSDK/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_windows-2.0.3/","dependencies":[]}],"web":[{"name":"image_picker_for_web","path":"/Users/jigafumakiya/Documents/FlutterSDK/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker_for_web-2.1.2/","dependencies":[]}]},"dependencyGraph":[{"name":"flutter_plugin_android_lifecycle","dependencies":[]},{"name":"flutter_share_me","dependencies":[]},{"name":"image_picker","dependencies":["flutter_plugin_android_lifecycle","image_picker_for_web"]},{"name":"image_picker_for_web","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_macos","path_provider_linux","path_provider_windows"]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_macos","dependencies":[]},{"name":"path_provider_windows","dependencies":[]}],"date_created":"2021-08-19 23:02:03.403314","version":"2.5.0-7.0.pre.158"} \ No newline at end of file +{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"flutter_share_me","path":"/Users/jigafumakiya/Documents/Jigar/plugin/open_flutter_share_me/flutter_share_me/","dependencies":[]},{"name":"image_picker","path":"/Users/jigafumakiya/Documents/FlutterSDK/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker-0.8.3+2/","dependencies":[]},{"name":"path_provider","path":"/Users/jigafumakiya/Documents/FlutterSDK/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-2.0.2/","dependencies":[]}],"android":[{"name":"flutter_plugin_android_lifecycle","path":"/Users/jigafumakiya/Documents/FlutterSDK/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_plugin_android_lifecycle-2.0.2/","dependencies":[]},{"name":"flutter_share_me","path":"/Users/jigafumakiya/Documents/Jigar/plugin/open_flutter_share_me/flutter_share_me/","dependencies":[]},{"name":"image_picker","path":"/Users/jigafumakiya/Documents/FlutterSDK/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker-0.8.3+2/","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"path_provider","path":"/Users/jigafumakiya/Documents/FlutterSDK/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-2.0.2/","dependencies":[]}],"macos":[{"name":"path_provider_macos","path":"/Users/jigafumakiya/Documents/FlutterSDK/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_macos-2.0.2/","dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"/Users/jigafumakiya/Documents/FlutterSDK/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_linux-2.0.2/","dependencies":[]}],"windows":[{"name":"path_provider_windows","path":"/Users/jigafumakiya/Documents/FlutterSDK/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_windows-2.0.3/","dependencies":[]}],"web":[{"name":"image_picker_for_web","path":"/Users/jigafumakiya/Documents/FlutterSDK/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker_for_web-2.1.2/","dependencies":[]}]},"dependencyGraph":[{"name":"flutter_plugin_android_lifecycle","dependencies":[]},{"name":"flutter_share_me","dependencies":[]},{"name":"image_picker","dependencies":["flutter_plugin_android_lifecycle","image_picker_for_web"]},{"name":"image_picker_for_web","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_macos","path_provider_linux","path_provider_windows"]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_macos","dependencies":[]},{"name":"path_provider_windows","dependencies":[]}],"date_created":"2021-08-23 23:26:20.576714","version":"2.5.0-7.0.pre.188"} \ No newline at end of file diff --git a/example/android/gradle/wrapper/gradle-wrapper.properties b/example/android/gradle/wrapper/gradle-wrapper.properties index 01a286e..29a33f1 100644 --- a/example/android/gradle/wrapper/gradle-wrapper.properties +++ b/example/android/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,6 @@ +#Thu Aug 19 23:16:09 IST 2021 distributionBase=GRADLE_USER_HOME +distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-rc-1-bin.zip distributionPath=wrapper/dists -zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip +zipStoreBase=GRADLE_USER_HOME diff --git a/example/ios/Flutter/flutter_export_environment.sh b/example/ios/Flutter/flutter_export_environment.sh index 735c2bc..6c21430 100755 --- a/example/ios/Flutter/flutter_export_environment.sh +++ b/example/ios/Flutter/flutter_export_environment.sh @@ -3,12 +3,11 @@ export "FLUTTER_ROOT=/Users/jigafumakiya/Documents/FlutterSDK/flutter" export "FLUTTER_APPLICATION_PATH=/Users/jigafumakiya/Documents/Jigar/plugin/open_flutter_share_me/flutter_share_me/example" export "COCOAPODS_PARALLEL_CODE_SIGN=true" -export "FLUTTER_TARGET=/Users/jigafumakiya/Documents/Jigar/plugin/open_flutter_share_me/flutter_share_me/example/lib/main.dart" +export "FLUTTER_TARGET=lib/main.dart" export "FLUTTER_BUILD_DIR=build" export "FLUTTER_BUILD_NAME=1.0.0" export "FLUTTER_BUILD_NUMBER=100" -export "DART_DEFINES=Zmx1dHRlci5pbnNwZWN0b3Iuc3RydWN0dXJlZEVycm9ycz10cnVl,RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ==" export "DART_OBFUSCATION=false" -export "TRACK_WIDGET_CREATION=true" +export "TRACK_WIDGET_CREATION=false" export "TREE_SHAKE_ICONS=false" -export "PACKAGE_CONFIG=/Users/jigafumakiya/Documents/Jigar/plugin/open_flutter_share_me/flutter_share_me/example/.dart_tool/package_config.json" +export "PACKAGE_CONFIG=.packages" diff --git a/example/lib/main.dart b/example/lib/main.dart index f575b6b..f7e8860 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -121,7 +121,7 @@ class _MyAppState extends State { break; case Share.whatsapp_personal: response = await flutterShareMe.shareWhatsAppPersonalMessage( - message: msg, phoneNumber: '918200188632'); + message: msg, phoneNumber: '+919574957435'); break; }