"Share Image" button for Android App - javascript

Lets say I have an Android html5 app with a picture generated with Javascript by passing a canvas to base64 and then appending it to DOM. I want to add some buttons to my app in order to share that image in, at least, Twitter and Facebook.
I've already seen how to trigger the "Intent" dialog with Java too. Is there any way to do that with Javascript?
Thanks.

Do you use PhoneGap?
If so, try this.
You cannot trigger an Intent dialogue from a regular web page.

If your app has an embedded WebView, you can use a javascript bridge to trigger the native share dialog.
The Android documentation has more info:
http://developer.android.com/reference/android/webkit/WebView.html
I gave a talk on creating a javascript bridge. Here are the slides:
http://www.sqisland.com/talks/progressive-webview

Related

How to detect "on Screenshot" with Javascript

I am making a web app similar to instagram and i want to detect and call a function whenever a user takes the screenshot, is their any way to implement this with javascript?
Currently, there is no way to handle a screenshot event through javascript. The screenshot functionality of phones simply has no connection to the browser.

Using fb:// To Share a Post through the Facebook App with Web Interface

One of my sites has a custom share plugin that I've written and I would like to try to get the 'sharing' feature to open up in the native Facebook app if possible. I know that you can use fb:// to open up the app but from what I've read, this is part of FBML which has been deprecated for several years. What I ideally would like is to have the link open up the FB app with a pre-populated link in the share box that the user could then just automatically share. Basically the functionality of the sharer.php script (it's ok if it pulls the data from the OG tags).
I know it can be done in iOS apps (and probably Android) but is it possible to do through a web interface?
I have the links I'm using only showing on mobile devices through some Javascript so I wouldn't have to worry about it causing any problems sitewide.
Thanks for your help!
var url = encodeURIComponent('http://example.org/');
window.open(
'https://www.facebook.com/sharer/sharer.php?u='+url,
'Share on Facebook',
'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600'
);
That's the simplest way I do it ;)

Detecting if a web app is bookmarked to homescreen in Android

I've built a responsive web app which utilises some simple HTML and jQuery. When the app is loaded in a mobile browser, a bootstrap modal() function is called which displays a simple 'bookmark to your homescreen' message.
For iOS I am able to check if the web app is being initialised from the homescreen bookmark via the following snippet:
if(!window.navigator.standalone){
$('#app-bookmarker').modal(); // popup the bookmark text
}
If so, the modal() function doesn't get called, thus no popup..
I'm struggling to find a simple way to achieve the same process for Android, has anyone done something similar? Issue at the moment is that the popup will continue to display even when bookmarked..
You can detect if the website has been added to the home screen in javascript like this:
if (window.matchMedia('(display-mode: standalone)').matches) {
console.log("Thank you for installing our app!");
}
More info on the official Google Developers documentation:
https://developers.google.com/web/updates/2015/10/display-mode
Unfortunately it doesn't look like you can currently. If you look at the Chrome Developer page for the install to homescreen (https://developer.chrome.com/multidevice/android/installtohomescreen), there's an FAQ which states it's not possible.
How can I detect if the app is running as an installed app?
You can’t, directly.
EDIT: Actually, if you create a manifest.json for the app, you can specify a start_url parameter, see https://developer.chrome.com/multidevice/android/installtohomescreen#supporting
It feels a bit hacky, but could you append a querystring to that URL, e.g. ?fromhomescreen=yes ? That way you can work out whether to display the popup or not based on that.

Prevent tweet URLs from being opened by native Twitter app on Android

I'm working on an app built in Titanium that has a few "Tweet about this" buttons. Since I can't use the Javascript part of a Tweet button as described in Twitter API, I just use a plain URL with parameters.
On Android, this causes problems. When users click this link, they get a choice how to open it: always the native browser, and additionally any app that has registered for this kind of link. So if the user has the Twitter app installed, Twitter will be shown as one of the options.
That would be great, except the Twitter app is awful. Most types of suggest-a-tweet URL cause the app to crash, and the few that do work don't pass the status text.
I'm looking for a way to force the URL to be opened by the native browser. (Or way to prevent the Twitter app from being among the options presented to the user, but that seems harder to do)
Is this possible using only the URL itself, or maybe a little Javascript? Since I'm using Titanium, Java won't help me.
I can't give you what you want but give you an alternative suggestion.
What you are trying is hard (often impossible to do without errors) even with native code as your trying to work against the OS. Intents are used in android as a way to let the user decide which program should handle a certain request. If you don't want the user to take this decision I'd suggest opening the url in a embedded browser.

browser automatically generate a launcher icon on home screen for web apps android

Is it possible to automatically generate a bookmark within the Android home screen using Javascript or a meta tag?
This is really only possible if you write native code along with your mobile site. If you do, then you can write a webview inside of your native code that will allow your javascript to invoke your native code and add the shortcut by intent.

Categories