Skip to content
Merged

Pr56 #70

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 65 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,69 @@
.DS_Store
.dart_tool/

# Created by https://www.toptal.com/developers/gitignore/api/flutter
# Edit at https://www.toptal.com/developers/gitignore?templates=flutter

### Flutter ###
# Flutter/Dart/Pub related
**/doc/api/
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.fvm/
.packages
.pub-cache/
.pub/
pubspec.lock

build/
coverage/
lib/generated_plugin_registrant.dart
# For library packages, don’t commit the pubspec.lock file.
# Regenerating the pubspec.lock file lets you test your package against the latest compatible versions of its dependencies.
# See https://dart.dev/guides/libraries/private-files#pubspeclock
#pubspec.lock

# Android related
**/android/**/gradle-wrapper.jar
**/android/.gradle
**/android/captures/
**/android/gradlew
**/android/gradlew.bat
**/android/key.properties
**/android/local.properties
**/android/**/GeneratedPluginRegistrant.java

# iOS/XCode related
**/ios/**/*.mode1v3
**/ios/**/*.mode2v3
**/ios/**/*.moved-aside
**/ios/**/*.pbxuser
**/ios/**/*.perspectivev3
**/ios/**/*sync/
**/ios/**/.sconsign.dblite
**/ios/**/.tags*
**/ios/**/.vagrant/
**/ios/**/DerivedData/
**/ios/**/Icon?
**/ios/**/Pods/
**/ios/**/.symlinks/
**/ios/**/profile
**/ios/**/xcuserdata
**/ios/.generated/
**/ios/Flutter/.last_build_id
**/ios/Flutter/App.framework
**/ios/Flutter/Flutter.framework
**/ios/Flutter/Flutter.podspec
**/ios/Flutter/Generated.xcconfig
**/ios/Flutter/app.flx
**/ios/Flutter/app.zip
**/ios/Flutter/flutter_assets/
**/ios/Flutter/flutter_export_environment.sh
**/ios/ServiceDefinitions.json
**/ios/Runner/GeneratedPluginRegistrant.*

# Exceptions to above rules.
!**/ios/**/default.mode1v3
!**/ios/**/default.mode2v3
!**/ios/**/default.pbxuser
!**/ios/**/default.perspectivev3
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages

# End of https://www.toptal.com/developers/gitignore/api/flutter
28 changes: 0 additions & 28 deletions .idea/libraries/Dart_SDK.xml

This file was deleted.

1 change: 1 addition & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
# 1.1.4
- fix #54 android share whatsapp failed(only text)

# 1.1.3
- fix #48 Update flutter_share_me.podspec

# 1.1.2
- change example demo

# 1.1.1
- readme

# 1.1.0
- Able to share direct message WhatsApp.
- Able to share video on Android & IOS WhatsApp.
- Able to share stories on Instagram.
- Breaking change- There is no more WhatsApp Business support on ios. if call WB in IOS throws method unImplemented error.

# 1.0.0

- support share image to whatsapp(Use image path instead of base64)
Expand Down
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

Flutter Plugin for sharing contents to social media.

You can use it share to Facebook , WhatsApp(WhatsAppBusiness) , Twitter And System Share UI.
You can use it share to Facebook , Instagram , WhatsApp(WhatsAppBusiness) , Twitter And System Share UI.
Support Url and Text.

support:
- Android & iOS : Facebook,WhatsApp(WhatsAppBusiness),Twitter,System Share
- Android & iOS : Facebook,WhatsApp(WhatsAppBusiness),Twitter,Instagram,System Share

**Note: This plugin is still under development, and some APIs might not be available yet.
Feedback and Pull Requests are most welcome!**
Expand Down Expand Up @@ -133,10 +133,21 @@ import 'package:flutter_share_me/flutter_share_me.dart';

## Methods

### facebook
#### shareToFacebook({String msg, String url})

### twitter
#### shareToTwitter({String msg, String url})

### whatsapp
#### shareToWhatsApp({String msg,String imagePath})
#### shareToWhatsApp4Biz({String msg,String imagePath})
#### shareToWhatsApp4Biz({String msg,String imagePath}) (only android)
#### shareWhatsAppPersonalMessage(String message ,String phoneNumber)

### instagram
#### shareToInstagram({String imagePath})

### system
#### shareToSystem({String msg}) use system share ui

These methods will return "success" if they successfully jump to the corresponding app.
Expand Down
13 changes: 12 additions & 1 deletion android/.settings/org.eclipse.buildship.core.prefs
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
connection.project.dir=../example/android
arguments=
auto.sync=false
build.scans.enabled=false
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
connection.project.dir=
eclipse.preferences.version=1
gradle.user.home=
java.home=C\:/Program Files/Eclipse Foundation/jdk-11.0.12.7-hotspot
jvm.arguments=
offline.mode=false
override.workspace.settings=true
show.console.view=true
show.executions.view=true
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class FlutterShareMePlugin implements MethodCallHandler, FlutterPlugin, A
final private static String _methodTwitter = "twitter_share";
final private static String _methodSystemShare = "system_share";
final private static String _methodInstagramShare = "instagram_share";

final private static String _methodTelegramShare = "telegram_share";


private Activity activity;
Expand Down Expand Up @@ -114,16 +114,20 @@ public void onMethodCall(MethodCall call, @NonNull Result result) {
break;
case _methodWhatsAppPersonal:
msg = call.argument("msg");
String phoneNumber = call.argument("phoneNumber");
shareWhatsAppPersonal(msg,phoneNumber , result);
String phoneNumber = call.argument("phoneNumber");
shareWhatsAppPersonal(msg, phoneNumber, result);
break;
case _methodSystemShare:
msg = call.argument("msg");
shareSystem(result, msg);
break;
case _methodInstagramShare:
msg = call.argument("url");
shareInstagramStory(msg,result);
shareInstagramStory(msg, result);
break;
case _methodTelegramShare:
msg = call.argument("msg");
shareToTelegram(msg, result);
break;
default:
result.notImplemented();
Expand Down Expand Up @@ -221,39 +225,65 @@ public void onError(FacebookException error) {
private void shareWhatsApp(String imagePath, String msg, Result result, boolean shareToWhatsAppBiz) {
try {
Intent whatsappIntent = new Intent(Intent.ACTION_SEND);
whatsappIntent.setType("text/plain");

whatsappIntent.setPackage(shareToWhatsAppBiz ? "com.whatsapp.w4b" : "com.whatsapp");
whatsappIntent.putExtra(Intent.EXTRA_TEXT, msg);
// if the url is the not empty then get url of the file and share
if (!TextUtils.isEmpty(imagePath)) {
whatsappIntent.setType("*/*");
System.out.print(imagePath+"url is not empty");
File file = new File(imagePath);
Uri fileUri = FileProvider.getUriForFile(activity, activity.getApplicationContext().getPackageName() + ".provider", file);
whatsappIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
whatsappIntent.putExtra(Intent.EXTRA_STREAM, fileUri);
whatsappIntent.setType("image/jpeg");
whatsappIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
else {
whatsappIntent.setType("text/plain");
}
activity.startActivity(whatsappIntent);
result.success("success");
} catch (Exception var9) {
result.error("error", var9.toString(), "");
}
}

/**
* share to telegram
*
* @param msg String
* @param result Result
*/

private void shareToTelegram(String msg, Result result) {
try {
Intent telegramIntent = new Intent(Intent.ACTION_SEND);
telegramIntent.setType("text/plain");
telegramIntent.setPackage("org.telegram.messenger");
telegramIntent.putExtra(Intent.EXTRA_TEXT, msg);
try {
activity.startActivity(telegramIntent);
result.success("true");
} catch (Exception ex) {
result.success("false:Telegram app is not installed on your device");
}
} catch (Exception var9) {
result.error("error", var9.toString(), "");
}
}
/**
* share whatsapp message to personal number
* @param msg String
*
* @param msg String
* @param phoneNumber String with country code
* @param result
*/
private void shareWhatsAppPersonal(String msg, String phoneNumber, Result 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");
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));
Expand All @@ -263,11 +293,12 @@ private void shareWhatsAppPersonal(String msg, String phoneNumber, Result resul

/**
* share to instagram
* @param url local image path
*
* @param url local image path
* @param result flutterResult
*/
private void shareInstagramStory(String url, Result result){
if(instagramInstalled()){
private void shareInstagramStory(String url, Result result) {
if (instagramInstalled()) {
File file = new File(url);
Uri fileUri = FileProvider.getUriForFile(activity, activity.getApplicationContext().getPackageName() + ".provider", file);

Expand All @@ -282,13 +313,9 @@ private void shareInstagramStory(String url, Result result){
e.printStackTrace();
result.success("Failure");
}

}else{
result.error("Instagram not found","Instagram is not installed on device.","");
} else {
result.error("Instagram not found", "Instagram is not installed on device.", "");
}



}

@Override
Expand All @@ -311,7 +338,6 @@ public void onDetachedFromActivity() {

}


///Utils methods
private boolean instagramInstalled() {
try {
Expand All @@ -320,7 +346,7 @@ private boolean instagramInstalled() {
.getApplicationInfo("com.instagram.android", 0);
return true;
} else {
Log.d("App","Instagram app is not installed on your device");
Log.d("App", "Instagram app is not installed on your device");
return false;
}
} catch (PackageManager.NameNotFoundException e) {
Expand Down
1 change: 0 additions & 1 deletion example/.flutter-plugins-dependencies

This file was deleted.

11 changes: 11 additions & 0 deletions example/android/.settings/org.eclipse.buildship.core.prefs
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
arguments=
auto.sync=false
build.scans.enabled=false
connection.gradle.distribution=GRADLE_DISTRIBUTION(VERSION(7.0-rc-1))
connection.project.dir=
eclipse.preferences.version=1
gradle.user.home=
java.home=C\:/Program Files/Eclipse Foundation/jdk-11.0.12.7-hotspot
jvm.arguments=
offline.mode=false
override.workspace.settings=true
show.console.view=true
show.executions.view=true
15 changes: 0 additions & 15 deletions example/ios/Flutter/flutter_export_environment.sh

This file was deleted.

Loading