How to add social sharing button in phonegap - phonegap-plugins

I am new to phonegap, I am creating a wishes/greeting app.I want to add a social button to share that greeting to people. The selected greeting should be share by Twitter, g+, WhatsApp and Facebook.

PhoneGap Social Sharing plugin for Android, iOS and Windows Phone:
I propose you to use the following plugin to add social sharing option. Its pretty simple and straight forward to use.
Social sharing link
Installation
Automatically (CLI / Plugman):
SocialSharing is compatible with Cordova Plugman, compatible with 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 with Cordova CLI, from npm:
$ cordova plugin add cordova-plugin-x-socialsharing
$ cordova prepare
SocialSharing.js is brought in automatically. There is no need to change or add anything in your html.
Manually
Add the following xml to all the config.xml files you can find:
<!-- for iOS -->
<feature name="SocialSharing">
<param name="ios-package" value="SocialSharing" />
</feature>
<!-- for Android (you will find one in res/xml) -->
<feature name="SocialSharing">
<param name="android-package" value="nl.xservices.plugins.SocialSharing" />
</feature>
<!-- for Windows Phone -->
<feature name="SocialSharing">
<param name="wp-package" value="SocialSharing"/>
</feature>
For sharing remote images (or other files) on Android, the file needs to be stored locally first, so add this permission to AndroidManifest.xml:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
For iOS, you'll need to add the Social.framework and MessageUI.framework to your project. Click your project, Build Phases, Link Binary With Libraries, search for and add Social.framework and MessageUI.framework.
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>
Download the source files for iOS and/or Android and copy them to your project.
iOS: Copy SocialSharing.h and SocialSharing.m to platforms/ios//Plugins
Android: Copy SocialSharing.java to platforms/android/src/nl/xservices/plugins (create the folders)
Window Phone: Copy SocialSharing.cs to platforms/wp8/Plugins/nl.x-services.plugins.socialsharing (create the folders)
PhoneGap Build
Just add the following xml to your config.xml to always use the latest version of this plugin (which is published to plugins.cordova.io these days):
<gap:plugin name="cordova-plugin-x-socialsharing" source="npm" />
or to use an older version, hosted at phonegap build:
<gap:plugin name="nl.x-services.plugins.socialsharing" version="4.3.16" />
SocialSharing.js is brought in automatically. Make sure though you include a reference to cordova.js in your index.html's head:
<script type="text/javascript" src="cordova.js"></script>
Using the share sheet
Here are some examples you can copy-paste to test the various combinations:
<button onclick="window.plugins.socialsharing.share('Message only')">message only</button>
<button onclick="window.plugins.socialsharing.share('Message and subject', 'The subject')">message and subject</button>
<button onclick="window.plugins.socialsharing.share(null, null, null, 'http://www.x-services.nl')">link only</button>
<button onclick="window.plugins.socialsharing.share('Message and link', null, null, 'http://www.x-services.nl')">message and link</button>
<button onclick="window.plugins.socialsharing.share(null, null, 'https://www.google.nl/images/srpr/logo4w.png', null)">image only</button>
// Beware: passing a base64 file as 'data:' is not supported on Android 2.x: https://code.google.com/p/android/issues/detail?id=7901#c43
// Hint: when sharing a base64 encoded file on Android you can set the filename by passing it as the subject (second param)
<button onclick="window.plugins.socialsharing.share(null, 'Android filename', 'data:image/png;base64,R0lGODlhDAAMALMBAP8AAP///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAUKAAEALAAAAAAMAAwAQAQZMMhJK7iY4p3nlZ8XgmNlnibXdVqolmhcRQA7', null)">base64 image only</button>
// Hint: you can share multiple files by using an array as thirds param: ['file 1','file 2', ..], but beware of this Android Kitkat Facebook issue: [#164]
<button onclick="window.plugins.socialsharing.share('Message and image', null, 'https://www.google.nl/images/srpr/logo4w.png', null)">message and image</button>
<button onclick="window.plugins.socialsharing.share('Message, image and link', null, 'https://www.google.nl/images/srpr/logo4w.png', 'http://www.x-services.nl')">message, image and link</button>
<button onclick="window.plugins.socialsharing.share('Message, subject, image and link', 'The subject', 'https://www.google.nl/images/srpr/logo4w.png', 'http://www.x-services.nl')">message, subject, image and link</button>
Sharing directly to..
Facebook
<button onclick="window.plugins.socialsharing.shareViaFacebook('Message via Facebook', null /* img */, null /* url */, function() {console.log('share ok')}, function(errormsg){alert(errormsg)})">msg via Facebook (with errcallback)</button>
Twitter
<!-- unlike most apps Twitter doesn't like it when you use an array to pass multiple files as the second param -->
<button onclick="window.plugins.socialsharing.shareViaTwitter('Message via Twitter')">message via Twitter</button>
<button onclick="window.plugins.socialsharing.shareViaTwitter('Message and link via Twitter', null /* img */, 'http://www.x-services.nl')">msg and link via Twitter</button>
WhatsApp
Note that on iOS when sharing an image and text, only the image is shared - let's hope WhatsApp creates a proper iOS extension to fix this.
Before using this method you may want to use canShareVia('whatsapp'.. (see below).
<button onclick="window.plugins.socialsharing.shareViaWhatsApp('Message via WhatsApp', null /* img */, null /* url */, function() {console.log('share ok')}, function(errormsg){alert(errormsg)})">msg via WhatsApp (with errcallback)</button>
If you want to know more please check the link..Social Sharing
If the answer helps you please Vote up. Cheers

Try to test it not using phonegap, but rather create platform version (for example: android) and then run it in Android Studio via your phone. I tried simulator but didn't work there as there is no WhatsApp or other social app in the simulator, that is why it will show you nothing.

Related

MediaScanner and ScopedStorage on SDK-29

the app i'm working on uses a File as a target for photo capturing. this is executed externally by user selecting a camera-app using Intent(ACTION_IMAGE_CAPTURE). since upgrading build and target-sdk to 29, there have been a series of issues starting with the restriction on freely accessing files on external storage. the first change was to use one of either the application's private-cache directory, eg:
File.createTempFile("tempImage", ".jpg", context.cacheDir)
or the applications private external-storage directory:
File.createTempFile("tempImage", ".jpg", context.getExternalFilesDir(Environment.DIRECTORY_PICTURES))
in combination with FileProvider access in file_paths.xml, eg:
<paths>
<external-path name="images" path="Pictures/" /><!-- prior to SDK-29, use public external storage -->
<external-files-path name="externalImages" path="Pictures/" />
<files-path name="internalImages" path="internalImages/"/>
<cache-path name="cache" path="/" />
</paths>
these work well now after being properly configured, however implementing "Save to Gallery" functionality, eg: notifying other apps of new images is no longer working on devices running Android-10
// use FileProvider to make this new photo publicly accessible
val shareableUri = FileProvider.getUriForFile(context, FILE_PROVIDER_AUTHORITY, newImage)
context.sendBroadcast(
Intent(ACTION_MEDIA_SCANNER_SCAN_FILE).apply { data = uris.externalUri }
)
this approach should work but doesn't, regardless of where the original image is saved (private-app-dir, cache-dir, external-private)
MediaScannerConnection.scanFile(context, arrayOf(newImage.absolutePath), arrayOf("image/jpeg")) { path: String, uri: Uri? ->
if (uri == null) {
throw IllegalStateException("media scan failed...")
} else {
// successful
}
}
Are there are new restrictions in Android's SDK-29 which necessitate a change in MediaScanning, specifically related to the way in which a (potentially) private image file is scanned? I noticed that MediaScanner methods mostly expect a String path instead of a URI, so this leads me to think that the new restrictions won't apply to it since its a system component.
Apps targeting Android 10 (API level 29) and higher are given scoped access into an external storage device, or scoped storage, by default.
so you need to make it compatible with scopedStorage but you can use this temporary approach for now mentioned in Google Android Developers guide.
Before your app is fully compatible with scoped storage, you can temporarily opt out based on your app's target SDK level or the requestLegacyExternalStorage manifest attribute:
<manifest ... >
<!-- This attribute is "false" by default on apps targeting
Android 10 or higher. -->
<application android:requestLegacyExternalStorage="true" ... >
...
</application>
</manifest>
visit this link for more info:
https://developer.android.com/training/data-storage/files/external-scoped

JHipster and Social login button

I have a project that is written in JHipster v4.9.0 and I am working on a upgrade to v 5.3.0.
I really miss the social login feature from earlier versions of JHipster and I need the social login buttons and service back in my project.
I have installed bootstrap social from
https://libraries.io/npm/bootstrap-social
with the command:
npm install bootstrap-social#5.1.1
Now I have in my package.json file the line
"bootstrap-social": "5.1.1",
Then I have in my login page
<a class="btn btn-block btn-social btn-facebook">
<span class="fa fa-facebook"></span>
Sign in with Facebook
</a>
But my problem is that I can not see the facebook logo on my button. Is there anything more I have to do to get the logo to show up?
The Facebook logo is using Font Awesome, which changed the imports in v5. First, add the following package in your package.json to the specified version (this includes brand icons such as social networks):
npm install --save #fortawesome/free-brands-svg-icons
You also need to import the icon in vendor.ts:
import {
faFacebook
} from '#fortawesome/free-brands-svg-icons';
....
library.add(faFacebook);
Finally, you need to add the icon in the HTML, similar to how others are used (but specify the fab for a Brand Icon). There are several examples in the navbar for icons, a Facebook icon will look like below:
<fa-icon [icon]="['fab', 'facebook']"></fa-icon>

Doesn't Azure AD B2C Page UI Customization Support Bootstrap?

I'm trying to customize the page UI on Azure AD B2C unified sign in/sign up page.
I was able to create my template and upload all the assets i.e. html page, images and css to my Azure Blob Storage container with the right CORS settings.
When I pull up the page, however, it looks absolutely HORRIBLE! It doesn't seem to support Bootstrap. I read somewhere that no JavaScript is allowed. Is that the reason for this?
Once I upload my custom HTML page, Azure AD B2C seems to be stripping off a lot of the design elements necessary for my customization such as id and style in my body tag -- see below:
<!-- Omitted for brevity -->
<body id="my-login-class" style="url: ('https://myazurestorage.blob.core.windows.net/my-container/my-bg-image.jpg')">
<div id="some-important-id" class="my-important-class">
<div class="col-xs-8">
<div>Some important message</div>
<div>
<div class="col-xs-4">
<div id="api">
</div>
</div>
</div>
</body>
When I inspect the page source once my custom page is rendered, I see that all my classes and Id's are removed along with Bootstrap references e.g. css and js.
Am I getting this right? No Bootstrap which means Azure AD B2C only supports customization of the most basic kind?
Your HTML template can include any external, head, or inline styles but it can't include scripts.
An example of a customized page can be found at the WoodGrove sign-up or sign-in page.
The HTML template for this customized page can be found in the WoodGrove GitHub repository.
This HTML template includes Bootstrap's Reboot styles as well as the WoodGrove's specific styles.
Azure AD B2C creates the head and body elements and then copies the child elements for each of these head and body elements from your HTML template to its HTML document.
Therefore, you shouldn't add attributes to the body element in your HTML template, because they aren't copied.
You can import the bootstrap references. Please see this document: https://learn.microsoft.com/en-us/dynamics365/customer-engagement/portals/azure-ad-b2c
See also: https://github.com/Azure-Samples/active-directory-b2c-php-webapp-openidconnect
It looks horrible for a reason. No styling is applied to the page so that it can be fully customizable. You can reference Bootstrap for CSS; however, I have run in to issues when using bootstrap.js for modals since it appears the Azure B2C API uses bootstrap for modals...In my experience, it is best to rely on Vanilla JS and to leave off any references to third-party JS.
It is possible to use JavaScript if you are using your own custom policies. There are some limitations to JavaScript and the best approach is to try to accomplish anything using the policy first.
To enable JavaScript use the following as guide:
<RelyingParty>
<DefaultUserJourney ReferenceId="SignUpOrSignIn" />
<UserJourneyBehaviors>
<ScriptExecution>Allow</ScriptExecution>
</UserJourneyBehaviors>
...
</RelyingParty>
When referencing external CSS/JS files, the URL must be absolute. This is true for the head section of HTML files as well as any references within JavaScript. Relative URL's can only be referenced within a CSS file.
Incorrect:
<link href="./css/assets.css" rel="stylesheet" type="text/css" />
Correct:
<link href="https://your-storage-account.blob.core.windows.net/your-container/css/assets.css" rel="stylesheet" type="text/css" />

How to Create custom App URL schemes for IOS using phonegap build?

I was searching for this problem since long time.finally i got the key answer.
How to create AppURL scheme for your own app.Here is the answer.
Simply use the following plugins into config.xml
<plugin name="cordova-plugin-customurlscheme">
<param name="URL_SCHEME" value="YourAppName" />
</plugin>
How to Get URL Scheme of any app?
-Right click on a app in iTunes, 'Show in Finder'
-Duplicate the app to Desktop
-Change .ipa to .zip
-Unzip and open the Payload folder
-Right click on app, 'Show Package Contents'
-Open 'Info.plist' in a text editor app like TextWrangler
-Search 'CFBundleURLSchemes'
-Between the tag you can find the URL

Google Sites Gadget with Javascript

I created a simple slideshow script to include on a Google Site for Google+ albums (it uses a library found at: https://sites.google.com/site/scriptsexamples/new-connectors-to-google-services/picasa-services). The test version worked except for the fact that if publish for anonymous access, it displays that aweful "This application was not created by Google" nonsense at the top. As this is a slideshow, I tried finding a way to avoid this. Thus I decided to try my hand at a Gadget. I opted to use Google Gadget Editor and combed through the internet to see how to do this (I am a complete noob with regards to gadgets, so excuse my ignorance...)
In the end I came up with this: http://hosting.gmodules.com/ig/gadgets/file/117039901033759910299/google-plus-slider.xml
Once I insert the gadget, I do not get any error messages and the frame does display on my google site (without the warning message, as far as I can tell), but nothing else happens. And I have no idea why.
Some notes:
the javascript works when it is a google apps script, published and then inserted in my site (but the warning message is ugly)
I have no idea whether it is even possible to call typical GAS calls such as Ui.App in XML gadget - if not, then I will have to learn, but don't know where.
Obviously the library that I am using needs to be loaded - I researched as much as I could but cannot find any way to load the library. The only option I could find was to include specific predefined libraries with the Required tag.
I hope you have all the info and that someone can help! Thanks in advance.
Do you get any Cross-Domain warnings in your console?
I would try and include the external library in your gadget-name.xml file. You're free to include (mostly) whatever JS you like under
<?xml version="1.0" encoding="UTF-8" ?>
<Module>
<ModulePrefs
title="Slider"
height="50"
width="200"
border="none"
/>
<Content type="html">
<![CDATA[
<script type="text/javascript">
function my-slide-show(){
//Dump your lib JS here
}
</script>
<div class="slideshowHtml"></div>
]]>
</Content>
</Module>
This will at least avoid any scoping / Cross origin worries you might be having

Resources