Skip to content

Commit

Permalink
Add methods const and Added send whatsapp message personal.
Browse files Browse the repository at this point in the history
  • Loading branch information
jigarfumakiya committed Aug 23, 2021
1 parent 7802d55 commit e03913c
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion example/.flutter-plugins-dependencies
Original file line number Diff line number Diff line change
@@ -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"}
{"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"}
5 changes: 3 additions & 2 deletions example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
7 changes: 3 additions & 4 deletions example/ios/Flutter/flutter_export_environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class _MyAppState extends State<MyApp> {
break;
case Share.whatsapp_personal:
response = await flutterShareMe.shareWhatsAppPersonalMessage(
message: msg, phoneNumber: '918200188632');
message: msg, phoneNumber: '+919574957435');
break;
}

Expand Down

0 comments on commit e03913c

Please sign in to comment.