Skip to content

πŸ‘¨β€β€οΈβ€πŸ’‹β€πŸ‘¨ Cordova plugin to share text, a file (image/PDF/..), or a URL (or all three) via the native sharing widget

License

Notifications You must be signed in to change notification settings

EddyVerbruggen/SocialSharing-PhoneGap-Plugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

17 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

PhoneGap Social Sharing plugin for Android and iOS6+

by Eddy Verbruggen

  1. Description
  2. Installation 2. Automatically (CLI / Plugman) 2. Manually 2. PhoneGap Build
  3. Usage
  4. Credits
  5. License

1. Description

This plugin allows you to use the native sharing window of your mobile device.

  • Works on Android, version 2.3.3 and higher (possibly even lower)
  • Works on iOS, version 6 and higher
  • Share text or an image (or both). Subject is also supported, when the receiving app supports it.
  • Supports sharing images from the internet, the local filesystem, or from the www folder
  • Compatible with Cordova Plugman and ready for PhoneGap 3.0
  • Officially supported by PhoneGap Build

iOS screenshot (options are based on what has been setup in the device settings):

ScreenShot

2. Installation

Automatically (CLI / Plugman)

SocialSharing is compatible with Cordova Plugman and ready for the PhoneGap 3.0 CLI, here's how it works with the CLI:

$ phonegap local plugin add https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin.git

or

$ cordova plugin add https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin.git

don't forget to run this command afterwards:

$ cordova build

Manually

1. Add the following xml to your config.xml in the root directory of your www folder:

<!-- for iOS -->
<feature name="SocialSharing">
	<param name="ios-package" value="SocialSharing" />
</feature>
<!-- for Android as plugin (deprecated) -->
<plugin name="SocialSharing" value="nl.xservices.plugins.SocialSharing"/>
<!-- for Android as feature -->
<feature name="SocialSharing">
  <param name="android-package" value="nl.xservices.plugins.SocialSharing" />
</feature>

Also for Android, images from the internet are only shareable with this permission added to AndroidManifest.xml:

<config-file target="AndroidManifest.xml" parent="/manifest">
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</config-file>

2. Grab a copy of SocialSharing.js, add it to your project and reference it in index.html:

<script type="text/javascript" src="js/SocialSharing.js"></script>

3. Download the source files for iOS and/or Android and copy them to your project.

iOS: Copy SocialSharing.h and SocialSharing.h to platforms/ios/<ProjectName>/Plugins

Android: Copy SocialSharing.java to platforms/android/src/nl/xservices/plugins (create the folders)

PhoneGap Build

SocialSharing works with PhoneGap build too. You can implement the plugin with these simple steps.

1. Add the following xml to your config.xml to always use the latest version of this plugin:

<gap:plugin name="nl.x-services.plugins.socialsharing" />

or to use this exact version:

<gap:plugin name="nl.x-services.plugins.socialsharing" version="2.0" />

2. Reference the JavaScript code in your index.html:

<!-- below <script src="phonegap.js"></script> -->
<script src="js/plugins/SocialSharing.js"></script>

3. Usage

// note: instead of available(), you could also check the useragent (android or ios6+)
window.plugins.socialsharing.available(function(isAvailable) {
  if (isAvailable) {
    // use a local image from inside the www folder:
    window.plugins.socialsharing.share('My text with a link: http://domain.com', 'My subject', 'www/image.gif'); // succes/error callback params may be added as 4th and 5th param
    // .. or a local image from anywhere else (if permitted):
    window.plugins.socialsharing.share('My text with a link: http://domain.com', 'My subject', '/Users/username/Library/Application Support/iPhone/6.1/Applications/25A1E7CF-079F-438D-823B-55C6F8CD2DC0/Documents/.nl.x-services.appname/pics/img.jpg');
    // .. or an image from the internet:
    window.plugins.socialsharing.share('My text with a link: http://domain.com', 'My subject', 'http://domain.com/image.jpg');
    // .. or only text:
    window.plugins.socialsharing.share('My text', null, null);
  }
});

4. CREDITS

This plugin was enhanced for Plugman / PhoneGap Build by Eddy Verbruggen. The Android code was entirely created by the author. The iOS code was inspired by Cameron Lerch. I also included a nice enhancement posted here to allow sharing files from the internet.

5. License

The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Bitdeli Badge

About

πŸ‘¨β€β€οΈβ€πŸ’‹β€πŸ‘¨ Cordova plugin to share text, a file (image/PDF/..), or a URL (or all three) via the native sharing widget

Resources

License

Stars

Watchers

Forks

Packages