From 6c23611438121eaeef5b9532031715931bb1cd96 Mon Sep 17 00:00:00 2001 From: "David.O" Date: Wed, 20 Jan 2021 10:40:50 +0000 Subject: [PATCH 1/2] add support for emailing multiple attachments (using android.intent.action.SEND_MULTIPLE) --- README.md | 19 ++ src/android/WebIntent.java | 537 +++++++++++++++++++------------------ www/webintent.js | 163 +++++------ 3 files changed, 381 insertions(+), 338 deletions(-) diff --git a/README.md b/README.md index 5f6885e..93fe34c 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,25 @@ OR ``` +## Sending Multiple Attachments + +You can now use this plugin to email multiple attachments as follows: + +```js + var email_attachments = [ + "file:///storage/emulated/0/Android/data/com.your_company.your_app/files/file1.pdf", + "file:///storage/emulated/0/Android/data/com.your_company.your_app/files/file2.csv" + ]; + + var external_extras = {}; + external_extras[window.plugins.webintent.EXTRA_STREAM] = email_attachments.join(); + external_extras[window.plugins.webintent.EXTRA_EMAIL] = ""; + external_extras[window.plugins.webintent.EXTRA_SUBJECT] = "My subject text"; + external_extras[window.plugins.webintent.EXTRA_TEXT] = "My email body text"; + + window.plugins.webintent.startActivity({action: window.plugins.webintent.ACTION_SEND_MULTIPLE, extras: external_extras, type: "text/plain"}, function() {console.log("Success!");}, function() {console.log("Failure!");}); +``` + ## Disclaimers - I'm not an Android nor Cordova Plugin developer, I have little knowledge on how Android and the plugin works, especially Intent. I just made this plugin works for my own purpose. I just copy & pasted code from other plugins to make it work. If you know how to clean up the code, please let me know. diff --git a/src/android/WebIntent.java b/src/android/WebIntent.java index 8fdf1d5..675b41b 100644 --- a/src/android/WebIntent.java +++ b/src/android/WebIntent.java @@ -1,257 +1,280 @@ -package com.borismus.webintent; - -import java.util.HashMap; -import java.util.Map; -import java.io.File; -import java.net.URI; -import java.net.URISyntaxException; - -import org.apache.cordova.CordovaActivity; -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.net.Uri; -import android.text.Html; -import android.util.Log; -import android.support.v4.content.FileProvider; -import android.os.Build; - -import org.apache.cordova.CallbackContext; -import org.apache.cordova.CordovaPlugin; -import org.apache.cordova.CordovaResourceApi; -import org.apache.cordova.PluginResult; - -/** - * WebIntent is a PhoneGap plugin that bridges Android intents and web - * applications: - * - * 1. Web apps can spawn intents that call native Android applications. - * 2. After setting up correct intent filters for Cordova applications, - * Android intents can be handled by Cordova web applications. - * - * @author Boris Smus (boris@borismus.com) - * @author Chris E. Kelley (chris@vetula.com) - * - */ -public class WebIntent extends CordovaPlugin { - private static final String LOG_TAG = "WebIntent"; - private static String installReferrer = null; - private CallbackContext onNewIntentCallbackContext = null; - - /** - * @return true iff if the action was executed successfully, else false. - */ - @Override - public boolean execute(String action, JSONArray args, CallbackContext callbackContext) { - try { - if ("startActivity".equals(action)) { - if (args.length() != 1) { - callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.INVALID_ACTION)); - return false; - } - // Parse the arguments - final CordovaResourceApi resourceApi = webView.getResourceApi(); - JSONObject obj = args.getJSONObject(0); - String type = obj.has("type") ? obj.getString("type") : null; - Uri uri = obj.has("url") ? resourceApi.remapUri(Uri.parse(obj.getString("url"))) : null; - JSONObject extras = obj.has("extras") ? obj.getJSONObject("extras") : null; - Map extrasMap = new HashMap(); - - // Populate the extras if any exist - if (extras != null) { - JSONArray extraNames = extras.names(); - for (int i = 0; i < extraNames.length(); i++) { - String key = extraNames.getString(i); - String value = extras.getString(key); - extrasMap.put(key, value); - } - } - - startActivity(obj.getString("action"), uri, type, extrasMap); - callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK)); - return true; - } else if ("hasExtra".equals(action)) { - if (args.length() != 1) { - callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.INVALID_ACTION)); - return false; - } - Intent i = ((CordovaActivity)this.cordova.getActivity()).getIntent(); - String extraName = args.getString(0); - callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, i.hasExtra(extraName))); - return true; - } else if ("getExtra".equals(action)) { - if (args.length() != 1) { - callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.INVALID_ACTION)); - return false; - } - Intent i = ((CordovaActivity)this.cordova.getActivity()).getIntent(); - String extraName = args.getString(0); - if (i.hasExtra(extraName)) { - callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, i.getStringExtra(extraName))); - return true; - } else { - callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR)); - return false; - } - } else if ("getUri".equals(action)) { - if (args.length() != 0) { - callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.INVALID_ACTION)); - return false; - } - Intent i = ((CordovaActivity)this.cordova.getActivity()).getIntent(); - String uri = i.getDataString(); - if (uri == null && installReferrer != null) { - uri = installReferrer; // App just installed, received play store referrer intent. - Log.i(LOG_TAG, String.format("URI is an install referrer: %s", installReferrer)); - } - callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, uri)); - return true; - } else if ("onNewIntent".equals(action)) { - // Save reference to the callback; will be called on "new intent" events. - this.onNewIntentCallbackContext = callbackContext; - - if (args.length() != 0) { - callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.INVALID_ACTION)); - return false; - } - - PluginResult result = new PluginResult(PluginResult.Status.NO_RESULT); - result.setKeepCallback(true); // Reuse the callback on intent events. - callbackContext.sendPluginResult(result); - return true; - } else if ("sendBroadcast".equals(action)) { - if (args.length() != 1) { - callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.INVALID_ACTION)); - return false; - } - - // Parse the arguments - JSONObject obj = args.getJSONObject(0); - - JSONObject extras = obj.has("extras") ? obj.getJSONObject("extras") : null; - Map extrasMap = new HashMap(); - - // Populate the extras if any exist - if (extras != null) { - JSONArray extraNames = extras.names(); - for (int i = 0; i < extraNames.length(); i++) { - String key = extraNames.getString(i); - String value = extras.getString(key); - extrasMap.put(key, value); - } - } - - sendBroadcast(obj.getString("action"), extrasMap); - callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK)); - return true; - } - callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.INVALID_ACTION)); - return false; - } catch (JSONException e) { - final String errorMessage = e.getMessage(); - Log.e(LOG_TAG, errorMessage); - callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION, errorMessage)); - return false; - } - } - - @Override - public void onNewIntent(Intent intent) { - super.onNewIntent(intent); - if (this.onNewIntentCallbackContext != null) { - //Kevin W: We only care about the Intent.EXTRA_STREAM - Uri streamUri = (Uri)intent.getParcelableExtra(Intent.EXTRA_STREAM); - if(streamUri!=null){ - PluginResult result = new PluginResult(PluginResult.Status.OK, streamUri.toString()); - result.setKeepCallback(true); - this.onNewIntentCallbackContext.sendPluginResult(result); - } - } - } - - void startActivity(String action, Uri uri, String type, Map extras) { - //Kevin W: Android 7.0 Nougat no longer allow file to be shared by file:// - //https://proandroiddev.com/sharing-files-though-intents-are-you-ready-for-nougat-70f7e9294a0b - if(newApi() && uri.getScheme().equals("file")){ - try{ - File fileToShare = new File(new URI(uri.toString())); - Uri contentUri = FileProvider.getUriForFile(this.cordova.getActivity(), - cordova.getActivity().getPackageName() + ".provider", - fileToShare); - - Intent shareIntent = new Intent(action); - shareIntent.putExtra(Intent.EXTRA_STREAM, contentUri); - shareIntent.setType(type); - shareIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); - shareIntent.setDataAndType(contentUri, type); - - ((CordovaActivity)this.cordova.getActivity()).startActivity(shareIntent); - return; - }catch(URISyntaxException e){ - final String errorMessage = e.getMessage(); - Log.e(LOG_TAG, errorMessage); - this.onNewIntentCallbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION, errorMessage)); - } - }else{ - Intent i = uri != null ? new Intent(action, uri) : new Intent(action); - if (type != null && uri != null) { - i.setDataAndType(uri, type); //Fix the crash problem with android 2.3.6 - } else { - if (type != null) { - i.setType(type); - } - } - - for (Map.Entry entry : extras.entrySet()) { - final String key = entry.getKey(); - final String value = entry.getValue(); - // If type is text/html, the extra text must be sent as HTML. - if (key.equals(Intent.EXTRA_TEXT) && "text/html".equals(type)) { - i.putExtra(key, Html.fromHtml(value)); - } else if (key.equals(Intent.EXTRA_STREAM)) { - // Allows sharing of images as attachments. - // `value` in this case should be the URI of a file. - final CordovaResourceApi resourceApi = webView.getResourceApi(); - i.putExtra(key, resourceApi.remapUri(Uri.parse(value))); - } else if (key.equals(Intent.EXTRA_EMAIL)) { - // Allows adding the email address of the receiver. - i.putExtra(Intent.EXTRA_EMAIL, new String[] { value }); - } else { - i.putExtra(key, value); - } - } - ((CordovaActivity)this.cordova.getActivity()).startActivity(i); - } - } - - void sendBroadcast(String action, Map extras) { - Intent intent = new Intent(); - intent.setAction(action); - for (Map.Entry entry : extras.entrySet()) { - intent.putExtra(entry.getKey(), entry.getValue()); - } - ((CordovaActivity)this.cordova.getActivity()).sendBroadcast(intent); - } - - // Receiver that listens for com.android.vending.INSTALL_REFERRER, an intent sent by the - // Play Store on installation when the referrer parameter of the install URL is populated: - // https://play.google.com/store/apps/details?id=|APP_ID|&referrer=|REFERRER| - public static class ReferralReceiver extends BroadcastReceiver { - private static final String LOG_TAG = "ReferralReceiver"; - - @Override - public void onReceive(Context context, Intent intent) { - // Store the install referrer so we can return it when getUri is called. - installReferrer = intent.getStringExtra("referrer"); - Log.i(LOG_TAG, String.format("Install referrer: %s", installReferrer)); - } - } - - private boolean newApi(){ - return Build.VERSION.SDK_INT >= Build.VERSION_CODES.N; - } -} +package com.borismus.webintent; + +import java.util.HashMap; +import java.util.Map; +import java.util.ArrayList; +import java.io.File; +import java.net.URI; +import java.net.URISyntaxException; + +import org.apache.cordova.CordovaActivity; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.net.Uri; +import android.text.Html; +import android.util.Log; +import android.support.v4.content.FileProvider; +import android.os.Build; + +import org.apache.cordova.CallbackContext; +import org.apache.cordova.CordovaPlugin; +import org.apache.cordova.CordovaResourceApi; +import org.apache.cordova.PluginResult; + +/** + * WebIntent is a PhoneGap plugin that bridges Android intents and web + * applications: + * + * 1. Web apps can spawn intents that call native Android applications. + * 2. After setting up correct intent filters for Cordova applications, + * Android intents can be handled by Cordova web applications. + * + * @author Boris Smus (boris@borismus.com) + * @author Chris E. Kelley (chris@vetula.com) + * + */ +public class WebIntent extends CordovaPlugin { + private static final String LOG_TAG = "WebIntent"; + private static String installReferrer = null; + private CallbackContext onNewIntentCallbackContext = null; + + /** + * @return true iff if the action was executed successfully, else false. + */ + @Override + public boolean execute(String action, JSONArray args, CallbackContext callbackContext) { + try { + if ("startActivity".equals(action)) { + if (args.length() != 1) { + callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.INVALID_ACTION)); + return false; + } + // Parse the arguments + final CordovaResourceApi resourceApi = webView.getResourceApi(); + JSONObject obj = args.getJSONObject(0); + String type = obj.has("type") ? obj.getString("type") : null; + Uri uri = obj.has("url") ? resourceApi.remapUri(Uri.parse(obj.getString("url"))) : null; + JSONObject extras = obj.has("extras") ? obj.getJSONObject("extras") : null; + Map extrasMap = new HashMap(); + + // Populate the extras if any exist + if (extras != null) { + JSONArray extraNames = extras.names(); + for (int i = 0; i < extraNames.length(); i++) { + String key = extraNames.getString(i); + String value = extras.getString(key); + extrasMap.put(key, value); + } + } + + startActivity(obj.getString("action"), uri, type, extrasMap); + callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK)); + return true; + } else if ("hasExtra".equals(action)) { + if (args.length() != 1) { + callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.INVALID_ACTION)); + return false; + } + Intent i = ((CordovaActivity)this.cordova.getActivity()).getIntent(); + String extraName = args.getString(0); + callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, i.hasExtra(extraName))); + return true; + } else if ("getExtra".equals(action)) { + if (args.length() != 1) { + callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.INVALID_ACTION)); + return false; + } + Intent i = ((CordovaActivity)this.cordova.getActivity()).getIntent(); + String extraName = args.getString(0); + if (i.hasExtra(extraName)) { + callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, i.getStringExtra(extraName))); + return true; + } else { + callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR)); + return false; + } + } else if ("getUri".equals(action)) { + if (args.length() != 0) { + callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.INVALID_ACTION)); + return false; + } + Intent i = ((CordovaActivity)this.cordova.getActivity()).getIntent(); + String uri = i.getDataString(); + if (uri == null && installReferrer != null) { + uri = installReferrer; // App just installed, received play store referrer intent. + Log.i(LOG_TAG, String.format("URI is an install referrer: %s", installReferrer)); + } + callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, uri)); + return true; + } else if ("onNewIntent".equals(action)) { + // Save reference to the callback; will be called on "new intent" events. + this.onNewIntentCallbackContext = callbackContext; + + if (args.length() != 0) { + callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.INVALID_ACTION)); + return false; + } + + PluginResult result = new PluginResult(PluginResult.Status.NO_RESULT); + result.setKeepCallback(true); // Reuse the callback on intent events. + callbackContext.sendPluginResult(result); + return true; + } else if ("sendBroadcast".equals(action)) { + if (args.length() != 1) { + callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.INVALID_ACTION)); + return false; + } + + // Parse the arguments + JSONObject obj = args.getJSONObject(0); + + JSONObject extras = obj.has("extras") ? obj.getJSONObject("extras") : null; + Map extrasMap = new HashMap(); + + // Populate the extras if any exist + if (extras != null) { + JSONArray extraNames = extras.names(); + for (int i = 0; i < extraNames.length(); i++) { + String key = extraNames.getString(i); + String value = extras.getString(key); + extrasMap.put(key, value); + } + } + + sendBroadcast(obj.getString("action"), extrasMap); + callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK)); + return true; + } + callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.INVALID_ACTION)); + return false; + } catch (JSONException e) { + final String errorMessage = e.getMessage(); + Log.e(LOG_TAG, errorMessage); + callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION, errorMessage)); + return false; + } + } + + @Override + public void onNewIntent(Intent intent) { + super.onNewIntent(intent); + if (this.onNewIntentCallbackContext != null) { + //Kevin W: We only care about the Intent.EXTRA_STREAM + Uri streamUri = (Uri)intent.getParcelableExtra(Intent.EXTRA_STREAM); + if(streamUri!=null){ + PluginResult result = new PluginResult(PluginResult.Status.OK, streamUri.toString()); + result.setKeepCallback(true); + this.onNewIntentCallbackContext.sendPluginResult(result); + } + } + } + + void startActivity(String action, Uri uri, String type, Map extras) { + + if (uri != null) { + String uri_string = uri.toString(); + Log.i(LOG_TAG, String.format("Start Activity : action = [%s], data = [%s]", action, uri_string)); + } + + //Kevin W: Android 7.0 Nougat no longer allow file to be shared by file:// + //https://proandroiddev.com/sharing-files-though-intents-are-you-ready-for-nougat-70f7e9294a0b + try{ + if(newApi() && (uri != null) && uri.getScheme().equals("file")){ + File fileToShare = new File(new URI(uri.toString())); + Uri contentUri = FileProvider.getUriForFile(this.cordova.getActivity(), + cordova.getActivity().getPackageName() + ".provider", + fileToShare); + + Intent shareIntent = new Intent(action); + shareIntent.putExtra(Intent.EXTRA_STREAM, contentUri); + shareIntent.setType(type); + shareIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + shareIntent.setDataAndType(contentUri, type); + + ((CordovaActivity)this.cordova.getActivity()).startActivity(shareIntent); + return; + }else{ + Intent i = uri != null ? new Intent(action, uri) : new Intent(action); + if (type != null && uri != null) { + i.setDataAndType(uri, type); //Fix the crash problem with android 2.3.6 + } else { + if (type != null) { + i.setType(type); + } + } + + for (Map.Entry entry : extras.entrySet()) { + final String key = entry.getKey(); + final String value = entry.getValue(); + + // If type is text/html, the extra text must be sent as HTML. + if (key.equals(Intent.EXTRA_TEXT) && "text/html".equals(type)) { + i.putExtra(key, Html.fromHtml(value)); + } else if (key.equals(Intent.EXTRA_STREAM)) { + if(action.equals(Intent.ACTION_SEND_MULTIPLE)) { + ArrayList extraUris = new ArrayList(); + for(String extraUri : value.split(",")) { + final CordovaResourceApi resourceApi = webView.getResourceApi(); + File fileToShare = new File(new URI(resourceApi.remapUri(Uri.parse(extraUri)).toString())); + Uri contentUri = FileProvider.getUriForFile(this.cordova.getActivity(), + cordova.getActivity().getPackageName() + ".provider", + fileToShare); + extraUris.add(contentUri); + } + i.putParcelableArrayListExtra(Intent.EXTRA_STREAM, extraUris); + i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + } + else { + // Allows sharing of images as attachments. + // `value` in this case should be the URI of a file. + final CordovaResourceApi resourceApi = webView.getResourceApi(); + i.putExtra(key, resourceApi.remapUri(Uri.parse(value))); + } + } else if (key.equals(Intent.EXTRA_EMAIL)) { + // Allows adding the email address of the receiver. + i.putExtra(Intent.EXTRA_EMAIL, new String[] { value }); + } else { + i.putExtra(key, value); + } + } + ((CordovaActivity)this.cordova.getActivity()).startActivity(i); + } + }catch(URISyntaxException e){ + final String errorMessage = e.getMessage(); + Log.e(LOG_TAG, errorMessage); + this.onNewIntentCallbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION, errorMessage)); + } + } + + void sendBroadcast(String action, Map extras) { + Intent intent = new Intent(); + intent.setAction(action); + for (Map.Entry entry : extras.entrySet()) { + intent.putExtra(entry.getKey(), entry.getValue()); + } + ((CordovaActivity)this.cordova.getActivity()).sendBroadcast(intent); + } + + // Receiver that listens for com.android.vending.INSTALL_REFERRER, an intent sent by the + // Play Store on installation when the referrer parameter of the install URL is populated: + // https://play.google.com/store/apps/details?id=|APP_ID|&referrer=|REFERRER| + public static class ReferralReceiver extends BroadcastReceiver { + private static final String LOG_TAG = "ReferralReceiver"; + + @Override + public void onReceive(Context context, Intent intent) { + // Store the install referrer so we can return it when getUri is called. + installReferrer = intent.getStringExtra("referrer"); + Log.i(LOG_TAG, String.format("Install referrer: %s", installReferrer)); + } + } + + private boolean newApi(){ + return Build.VERSION.SDK_INT >= Build.VERSION_CODES.N; + } +} diff --git a/www/webintent.js b/www/webintent.js index 7120c25..1f6b7d3 100644 --- a/www/webintent.js +++ b/www/webintent.js @@ -1,81 +1,82 @@ -/** - * cordova Web Intent plugin - * Copyright (c) Boris Smus 2010 - * - */ - (function(cordova){ - var WebIntent = function() { - - }; - - WebIntent.prototype.ACTION_SEND = "android.intent.action.SEND"; - WebIntent.prototype.ACTION_VIEW= "android.intent.action.VIEW"; - WebIntent.prototype.EXTRA_TEXT = "android.intent.extra.TEXT"; - WebIntent.prototype.EXTRA_SUBJECT = "android.intent.extra.SUBJECT"; - WebIntent.prototype.EXTRA_STREAM = "android.intent.extra.STREAM"; - WebIntent.prototype.EXTRA_EMAIL = "android.intent.extra.EMAIL"; - WebIntent.prototype.ACTION_CALL = "android.intent.action.CALL"; - WebIntent.prototype.ACTION_SENDTO = "android.intent.action.SENDTO"; - - WebIntent.prototype.startActivity = function(params, success, fail) { - return cordova.exec(function(args) { - success(args); - }, function(args) { - fail(args); - }, 'WebIntent', 'startActivity', [params]); - }; - - WebIntent.prototype.hasExtra = function(params, success, fail) { - return cordova.exec(function(args) { - success(args); - }, function(args) { - fail(args); - }, 'WebIntent', 'hasExtra', [params]); - }; - - WebIntent.prototype.getUri = function(success, fail) { - return cordova.exec(function(args) { - success(args); - }, function(args) { - fail(args); - }, 'WebIntent', 'getUri', []); - }; - - WebIntent.prototype.getExtra = function(params, success, fail) { - return cordova.exec(function(args) { - success(args); - }, function(args) { - fail(args); - }, 'WebIntent', 'getExtra', [params]); - }; - - - WebIntent.prototype.onNewIntent = function(callback) { - return cordova.exec(function(args) { - callback(args); - }, function(args) { - }, 'WebIntent', 'onNewIntent', []); - }; - - WebIntent.prototype.sendBroadcast = function(params, success, fail) { - return cordova.exec(function(args) { - success(args); - }, function(args) { - fail(args); - }, 'WebIntent', 'sendBroadcast', [params]); - }; - - WebIntent.prototype.removeExtra = function(params, success, fail) { - return cordova.exec(function(args) { - success(args); - }, function(args) { - fail(args); - }, 'WebIntent', 'removeExtra', [params]); - }; - - window.webintent = new WebIntent(); - - // backwards compatibility - window.plugins = window.plugins || {}; - window.plugins.webintent = window.webintent; -})(window.PhoneGap || window.Cordova || window.cordova); +/** + * cordova Web Intent plugin + * Copyright (c) Boris Smus 2010 + * + */ + (function(cordova){ + var WebIntent = function() { + + }; + + WebIntent.prototype.ACTION_SEND = "android.intent.action.SEND"; + WebIntent.prototype.ACTION_SEND_MULTIPLE = "android.intent.action.SEND_MULTIPLE"; + WebIntent.prototype.ACTION_VIEW= "android.intent.action.VIEW"; + WebIntent.prototype.EXTRA_TEXT = "android.intent.extra.TEXT"; + WebIntent.prototype.EXTRA_SUBJECT = "android.intent.extra.SUBJECT"; + WebIntent.prototype.EXTRA_STREAM = "android.intent.extra.STREAM"; + WebIntent.prototype.EXTRA_EMAIL = "android.intent.extra.EMAIL"; + WebIntent.prototype.ACTION_CALL = "android.intent.action.CALL"; + WebIntent.prototype.ACTION_SENDTO = "android.intent.action.SENDTO"; + + WebIntent.prototype.startActivity = function(params, success, fail) { + return cordova.exec(function(args) { + success(args); + }, function(args) { + fail(args); + }, 'WebIntent', 'startActivity', [params]); + }; + + WebIntent.prototype.hasExtra = function(params, success, fail) { + return cordova.exec(function(args) { + success(args); + }, function(args) { + fail(args); + }, 'WebIntent', 'hasExtra', [params]); + }; + + WebIntent.prototype.getUri = function(success, fail) { + return cordova.exec(function(args) { + success(args); + }, function(args) { + fail(args); + }, 'WebIntent', 'getUri', []); + }; + + WebIntent.prototype.getExtra = function(params, success, fail) { + return cordova.exec(function(args) { + success(args); + }, function(args) { + fail(args); + }, 'WebIntent', 'getExtra', [params]); + }; + + + WebIntent.prototype.onNewIntent = function(callback) { + return cordova.exec(function(args) { + callback(args); + }, function(args) { + }, 'WebIntent', 'onNewIntent', []); + }; + + WebIntent.prototype.sendBroadcast = function(params, success, fail) { + return cordova.exec(function(args) { + success(args); + }, function(args) { + fail(args); + }, 'WebIntent', 'sendBroadcast', [params]); + }; + + WebIntent.prototype.removeExtra = function(params, success, fail) { + return cordova.exec(function(args) { + success(args); + }, function(args) { + fail(args); + }, 'WebIntent', 'removeExtra', [params]); + }; + + window.webintent = new WebIntent(); + + // backwards compatibility + window.plugins = window.plugins || {}; + window.plugins.webintent = window.webintent; +})(window.PhoneGap || window.Cordova || window.cordova); From 1f5813f1c6347769899863081c0c360545ab389e Mon Sep 17 00:00:00 2001 From: "David.O" Date: Wed, 20 Jan 2021 12:26:10 +0000 Subject: [PATCH 2/2] fix line endings --- src/android/WebIntent.java | 560 ++++++++++++++++++------------------- www/webintent.js | 164 +++++------ 2 files changed, 362 insertions(+), 362 deletions(-) diff --git a/src/android/WebIntent.java b/src/android/WebIntent.java index 675b41b..3790960 100644 --- a/src/android/WebIntent.java +++ b/src/android/WebIntent.java @@ -1,280 +1,280 @@ -package com.borismus.webintent; - -import java.util.HashMap; -import java.util.Map; -import java.util.ArrayList; -import java.io.File; -import java.net.URI; -import java.net.URISyntaxException; - -import org.apache.cordova.CordovaActivity; -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.net.Uri; -import android.text.Html; -import android.util.Log; -import android.support.v4.content.FileProvider; -import android.os.Build; - -import org.apache.cordova.CallbackContext; -import org.apache.cordova.CordovaPlugin; -import org.apache.cordova.CordovaResourceApi; -import org.apache.cordova.PluginResult; - -/** - * WebIntent is a PhoneGap plugin that bridges Android intents and web - * applications: - * - * 1. Web apps can spawn intents that call native Android applications. - * 2. After setting up correct intent filters for Cordova applications, - * Android intents can be handled by Cordova web applications. - * - * @author Boris Smus (boris@borismus.com) - * @author Chris E. Kelley (chris@vetula.com) - * - */ -public class WebIntent extends CordovaPlugin { - private static final String LOG_TAG = "WebIntent"; - private static String installReferrer = null; - private CallbackContext onNewIntentCallbackContext = null; - - /** - * @return true iff if the action was executed successfully, else false. - */ - @Override - public boolean execute(String action, JSONArray args, CallbackContext callbackContext) { - try { - if ("startActivity".equals(action)) { - if (args.length() != 1) { - callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.INVALID_ACTION)); - return false; - } - // Parse the arguments - final CordovaResourceApi resourceApi = webView.getResourceApi(); - JSONObject obj = args.getJSONObject(0); - String type = obj.has("type") ? obj.getString("type") : null; - Uri uri = obj.has("url") ? resourceApi.remapUri(Uri.parse(obj.getString("url"))) : null; - JSONObject extras = obj.has("extras") ? obj.getJSONObject("extras") : null; - Map extrasMap = new HashMap(); - - // Populate the extras if any exist - if (extras != null) { - JSONArray extraNames = extras.names(); - for (int i = 0; i < extraNames.length(); i++) { - String key = extraNames.getString(i); - String value = extras.getString(key); - extrasMap.put(key, value); - } - } - - startActivity(obj.getString("action"), uri, type, extrasMap); - callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK)); - return true; - } else if ("hasExtra".equals(action)) { - if (args.length() != 1) { - callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.INVALID_ACTION)); - return false; - } - Intent i = ((CordovaActivity)this.cordova.getActivity()).getIntent(); - String extraName = args.getString(0); - callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, i.hasExtra(extraName))); - return true; - } else if ("getExtra".equals(action)) { - if (args.length() != 1) { - callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.INVALID_ACTION)); - return false; - } - Intent i = ((CordovaActivity)this.cordova.getActivity()).getIntent(); - String extraName = args.getString(0); - if (i.hasExtra(extraName)) { - callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, i.getStringExtra(extraName))); - return true; - } else { - callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR)); - return false; - } - } else if ("getUri".equals(action)) { - if (args.length() != 0) { - callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.INVALID_ACTION)); - return false; - } - Intent i = ((CordovaActivity)this.cordova.getActivity()).getIntent(); - String uri = i.getDataString(); - if (uri == null && installReferrer != null) { - uri = installReferrer; // App just installed, received play store referrer intent. - Log.i(LOG_TAG, String.format("URI is an install referrer: %s", installReferrer)); - } - callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, uri)); - return true; - } else if ("onNewIntent".equals(action)) { - // Save reference to the callback; will be called on "new intent" events. - this.onNewIntentCallbackContext = callbackContext; - - if (args.length() != 0) { - callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.INVALID_ACTION)); - return false; - } - - PluginResult result = new PluginResult(PluginResult.Status.NO_RESULT); - result.setKeepCallback(true); // Reuse the callback on intent events. - callbackContext.sendPluginResult(result); - return true; - } else if ("sendBroadcast".equals(action)) { - if (args.length() != 1) { - callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.INVALID_ACTION)); - return false; - } - - // Parse the arguments - JSONObject obj = args.getJSONObject(0); - - JSONObject extras = obj.has("extras") ? obj.getJSONObject("extras") : null; - Map extrasMap = new HashMap(); - - // Populate the extras if any exist - if (extras != null) { - JSONArray extraNames = extras.names(); - for (int i = 0; i < extraNames.length(); i++) { - String key = extraNames.getString(i); - String value = extras.getString(key); - extrasMap.put(key, value); - } - } - - sendBroadcast(obj.getString("action"), extrasMap); - callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK)); - return true; - } - callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.INVALID_ACTION)); - return false; - } catch (JSONException e) { - final String errorMessage = e.getMessage(); - Log.e(LOG_TAG, errorMessage); - callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION, errorMessage)); - return false; - } - } - - @Override - public void onNewIntent(Intent intent) { - super.onNewIntent(intent); - if (this.onNewIntentCallbackContext != null) { - //Kevin W: We only care about the Intent.EXTRA_STREAM - Uri streamUri = (Uri)intent.getParcelableExtra(Intent.EXTRA_STREAM); - if(streamUri!=null){ - PluginResult result = new PluginResult(PluginResult.Status.OK, streamUri.toString()); - result.setKeepCallback(true); - this.onNewIntentCallbackContext.sendPluginResult(result); - } - } - } - - void startActivity(String action, Uri uri, String type, Map extras) { - - if (uri != null) { - String uri_string = uri.toString(); - Log.i(LOG_TAG, String.format("Start Activity : action = [%s], data = [%s]", action, uri_string)); - } - - //Kevin W: Android 7.0 Nougat no longer allow file to be shared by file:// - //https://proandroiddev.com/sharing-files-though-intents-are-you-ready-for-nougat-70f7e9294a0b - try{ - if(newApi() && (uri != null) && uri.getScheme().equals("file")){ - File fileToShare = new File(new URI(uri.toString())); - Uri contentUri = FileProvider.getUriForFile(this.cordova.getActivity(), - cordova.getActivity().getPackageName() + ".provider", - fileToShare); - - Intent shareIntent = new Intent(action); - shareIntent.putExtra(Intent.EXTRA_STREAM, contentUri); - shareIntent.setType(type); - shareIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); - shareIntent.setDataAndType(contentUri, type); - - ((CordovaActivity)this.cordova.getActivity()).startActivity(shareIntent); - return; - }else{ - Intent i = uri != null ? new Intent(action, uri) : new Intent(action); - if (type != null && uri != null) { - i.setDataAndType(uri, type); //Fix the crash problem with android 2.3.6 - } else { - if (type != null) { - i.setType(type); - } - } - - for (Map.Entry entry : extras.entrySet()) { - final String key = entry.getKey(); - final String value = entry.getValue(); - - // If type is text/html, the extra text must be sent as HTML. - if (key.equals(Intent.EXTRA_TEXT) && "text/html".equals(type)) { - i.putExtra(key, Html.fromHtml(value)); - } else if (key.equals(Intent.EXTRA_STREAM)) { - if(action.equals(Intent.ACTION_SEND_MULTIPLE)) { - ArrayList extraUris = new ArrayList(); - for(String extraUri : value.split(",")) { - final CordovaResourceApi resourceApi = webView.getResourceApi(); - File fileToShare = new File(new URI(resourceApi.remapUri(Uri.parse(extraUri)).toString())); - Uri contentUri = FileProvider.getUriForFile(this.cordova.getActivity(), - cordova.getActivity().getPackageName() + ".provider", - fileToShare); - extraUris.add(contentUri); - } - i.putParcelableArrayListExtra(Intent.EXTRA_STREAM, extraUris); - i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); - } - else { - // Allows sharing of images as attachments. - // `value` in this case should be the URI of a file. - final CordovaResourceApi resourceApi = webView.getResourceApi(); - i.putExtra(key, resourceApi.remapUri(Uri.parse(value))); - } - } else if (key.equals(Intent.EXTRA_EMAIL)) { - // Allows adding the email address of the receiver. - i.putExtra(Intent.EXTRA_EMAIL, new String[] { value }); - } else { - i.putExtra(key, value); - } - } - ((CordovaActivity)this.cordova.getActivity()).startActivity(i); - } - }catch(URISyntaxException e){ - final String errorMessage = e.getMessage(); - Log.e(LOG_TAG, errorMessage); - this.onNewIntentCallbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION, errorMessage)); - } - } - - void sendBroadcast(String action, Map extras) { - Intent intent = new Intent(); - intent.setAction(action); - for (Map.Entry entry : extras.entrySet()) { - intent.putExtra(entry.getKey(), entry.getValue()); - } - ((CordovaActivity)this.cordova.getActivity()).sendBroadcast(intent); - } - - // Receiver that listens for com.android.vending.INSTALL_REFERRER, an intent sent by the - // Play Store on installation when the referrer parameter of the install URL is populated: - // https://play.google.com/store/apps/details?id=|APP_ID|&referrer=|REFERRER| - public static class ReferralReceiver extends BroadcastReceiver { - private static final String LOG_TAG = "ReferralReceiver"; - - @Override - public void onReceive(Context context, Intent intent) { - // Store the install referrer so we can return it when getUri is called. - installReferrer = intent.getStringExtra("referrer"); - Log.i(LOG_TAG, String.format("Install referrer: %s", installReferrer)); - } - } - - private boolean newApi(){ - return Build.VERSION.SDK_INT >= Build.VERSION_CODES.N; - } -} +package com.borismus.webintent; + +import java.util.HashMap; +import java.util.Map; +import java.util.ArrayList; +import java.io.File; +import java.net.URI; +import java.net.URISyntaxException; + +import org.apache.cordova.CordovaActivity; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.net.Uri; +import android.text.Html; +import android.util.Log; +import android.support.v4.content.FileProvider; +import android.os.Build; + +import org.apache.cordova.CallbackContext; +import org.apache.cordova.CordovaPlugin; +import org.apache.cordova.CordovaResourceApi; +import org.apache.cordova.PluginResult; + +/** + * WebIntent is a PhoneGap plugin that bridges Android intents and web + * applications: + * + * 1. Web apps can spawn intents that call native Android applications. + * 2. After setting up correct intent filters for Cordova applications, + * Android intents can be handled by Cordova web applications. + * + * @author Boris Smus (boris@borismus.com) + * @author Chris E. Kelley (chris@vetula.com) + * + */ +public class WebIntent extends CordovaPlugin { + private static final String LOG_TAG = "WebIntent"; + private static String installReferrer = null; + private CallbackContext onNewIntentCallbackContext = null; + + /** + * @return true iff if the action was executed successfully, else false. + */ + @Override + public boolean execute(String action, JSONArray args, CallbackContext callbackContext) { + try { + if ("startActivity".equals(action)) { + if (args.length() != 1) { + callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.INVALID_ACTION)); + return false; + } + // Parse the arguments + final CordovaResourceApi resourceApi = webView.getResourceApi(); + JSONObject obj = args.getJSONObject(0); + String type = obj.has("type") ? obj.getString("type") : null; + Uri uri = obj.has("url") ? resourceApi.remapUri(Uri.parse(obj.getString("url"))) : null; + JSONObject extras = obj.has("extras") ? obj.getJSONObject("extras") : null; + Map extrasMap = new HashMap(); + + // Populate the extras if any exist + if (extras != null) { + JSONArray extraNames = extras.names(); + for (int i = 0; i < extraNames.length(); i++) { + String key = extraNames.getString(i); + String value = extras.getString(key); + extrasMap.put(key, value); + } + } + + startActivity(obj.getString("action"), uri, type, extrasMap); + callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK)); + return true; + } else if ("hasExtra".equals(action)) { + if (args.length() != 1) { + callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.INVALID_ACTION)); + return false; + } + Intent i = ((CordovaActivity)this.cordova.getActivity()).getIntent(); + String extraName = args.getString(0); + callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, i.hasExtra(extraName))); + return true; + } else if ("getExtra".equals(action)) { + if (args.length() != 1) { + callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.INVALID_ACTION)); + return false; + } + Intent i = ((CordovaActivity)this.cordova.getActivity()).getIntent(); + String extraName = args.getString(0); + if (i.hasExtra(extraName)) { + callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, i.getStringExtra(extraName))); + return true; + } else { + callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR)); + return false; + } + } else if ("getUri".equals(action)) { + if (args.length() != 0) { + callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.INVALID_ACTION)); + return false; + } + Intent i = ((CordovaActivity)this.cordova.getActivity()).getIntent(); + String uri = i.getDataString(); + if (uri == null && installReferrer != null) { + uri = installReferrer; // App just installed, received play store referrer intent. + Log.i(LOG_TAG, String.format("URI is an install referrer: %s", installReferrer)); + } + callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, uri)); + return true; + } else if ("onNewIntent".equals(action)) { + // Save reference to the callback; will be called on "new intent" events. + this.onNewIntentCallbackContext = callbackContext; + + if (args.length() != 0) { + callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.INVALID_ACTION)); + return false; + } + + PluginResult result = new PluginResult(PluginResult.Status.NO_RESULT); + result.setKeepCallback(true); // Reuse the callback on intent events. + callbackContext.sendPluginResult(result); + return true; + } else if ("sendBroadcast".equals(action)) { + if (args.length() != 1) { + callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.INVALID_ACTION)); + return false; + } + + // Parse the arguments + JSONObject obj = args.getJSONObject(0); + + JSONObject extras = obj.has("extras") ? obj.getJSONObject("extras") : null; + Map extrasMap = new HashMap(); + + // Populate the extras if any exist + if (extras != null) { + JSONArray extraNames = extras.names(); + for (int i = 0; i < extraNames.length(); i++) { + String key = extraNames.getString(i); + String value = extras.getString(key); + extrasMap.put(key, value); + } + } + + sendBroadcast(obj.getString("action"), extrasMap); + callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK)); + return true; + } + callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.INVALID_ACTION)); + return false; + } catch (JSONException e) { + final String errorMessage = e.getMessage(); + Log.e(LOG_TAG, errorMessage); + callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION, errorMessage)); + return false; + } + } + + @Override + public void onNewIntent(Intent intent) { + super.onNewIntent(intent); + if (this.onNewIntentCallbackContext != null) { + //Kevin W: We only care about the Intent.EXTRA_STREAM + Uri streamUri = (Uri)intent.getParcelableExtra(Intent.EXTRA_STREAM); + if(streamUri!=null){ + PluginResult result = new PluginResult(PluginResult.Status.OK, streamUri.toString()); + result.setKeepCallback(true); + this.onNewIntentCallbackContext.sendPluginResult(result); + } + } + } + + void startActivity(String action, Uri uri, String type, Map extras) { + + if (uri != null) { + String uri_string = uri.toString(); + Log.i(LOG_TAG, String.format("Start Activity : action = [%s], data = [%s]", action, uri_string)); + } + + //Kevin W: Android 7.0 Nougat no longer allow file to be shared by file:// + //https://proandroiddev.com/sharing-files-though-intents-are-you-ready-for-nougat-70f7e9294a0b + try{ + if(newApi() && (uri != null) && uri.getScheme().equals("file")){ + File fileToShare = new File(new URI(uri.toString())); + Uri contentUri = FileProvider.getUriForFile(this.cordova.getActivity(), + cordova.getActivity().getPackageName() + ".provider", + fileToShare); + + Intent shareIntent = new Intent(action); + shareIntent.putExtra(Intent.EXTRA_STREAM, contentUri); + shareIntent.setType(type); + shareIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + shareIntent.setDataAndType(contentUri, type); + + ((CordovaActivity)this.cordova.getActivity()).startActivity(shareIntent); + return; + }else{ + Intent i = uri != null ? new Intent(action, uri) : new Intent(action); + if (type != null && uri != null) { + i.setDataAndType(uri, type); //Fix the crash problem with android 2.3.6 + } else { + if (type != null) { + i.setType(type); + } + } + + for (Map.Entry entry : extras.entrySet()) { + final String key = entry.getKey(); + final String value = entry.getValue(); + + // If type is text/html, the extra text must be sent as HTML. + if (key.equals(Intent.EXTRA_TEXT) && "text/html".equals(type)) { + i.putExtra(key, Html.fromHtml(value)); + } else if (key.equals(Intent.EXTRA_STREAM)) { + if(action.equals(Intent.ACTION_SEND_MULTIPLE)) { + ArrayList extraUris = new ArrayList(); + for(String extraUri : value.split(",")) { + final CordovaResourceApi resourceApi = webView.getResourceApi(); + File fileToShare = new File(new URI(resourceApi.remapUri(Uri.parse(extraUri)).toString())); + Uri contentUri = FileProvider.getUriForFile(this.cordova.getActivity(), + cordova.getActivity().getPackageName() + ".provider", + fileToShare); + extraUris.add(contentUri); + } + i.putParcelableArrayListExtra(Intent.EXTRA_STREAM, extraUris); + i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + } + else { + // Allows sharing of images as attachments. + // `value` in this case should be the URI of a file. + final CordovaResourceApi resourceApi = webView.getResourceApi(); + i.putExtra(key, resourceApi.remapUri(Uri.parse(value))); + } + } else if (key.equals(Intent.EXTRA_EMAIL)) { + // Allows adding the email address of the receiver. + i.putExtra(Intent.EXTRA_EMAIL, new String[] { value }); + } else { + i.putExtra(key, value); + } + } + ((CordovaActivity)this.cordova.getActivity()).startActivity(i); + } + }catch(URISyntaxException e){ + final String errorMessage = e.getMessage(); + Log.e(LOG_TAG, errorMessage); + this.onNewIntentCallbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION, errorMessage)); + } + } + + void sendBroadcast(String action, Map extras) { + Intent intent = new Intent(); + intent.setAction(action); + for (Map.Entry entry : extras.entrySet()) { + intent.putExtra(entry.getKey(), entry.getValue()); + } + ((CordovaActivity)this.cordova.getActivity()).sendBroadcast(intent); + } + + // Receiver that listens for com.android.vending.INSTALL_REFERRER, an intent sent by the + // Play Store on installation when the referrer parameter of the install URL is populated: + // https://play.google.com/store/apps/details?id=|APP_ID|&referrer=|REFERRER| + public static class ReferralReceiver extends BroadcastReceiver { + private static final String LOG_TAG = "ReferralReceiver"; + + @Override + public void onReceive(Context context, Intent intent) { + // Store the install referrer so we can return it when getUri is called. + installReferrer = intent.getStringExtra("referrer"); + Log.i(LOG_TAG, String.format("Install referrer: %s", installReferrer)); + } + } + + private boolean newApi(){ + return Build.VERSION.SDK_INT >= Build.VERSION_CODES.N; + } +} diff --git a/www/webintent.js b/www/webintent.js index 1f6b7d3..a206f5c 100644 --- a/www/webintent.js +++ b/www/webintent.js @@ -1,82 +1,82 @@ -/** - * cordova Web Intent plugin - * Copyright (c) Boris Smus 2010 - * - */ - (function(cordova){ - var WebIntent = function() { - - }; - - WebIntent.prototype.ACTION_SEND = "android.intent.action.SEND"; - WebIntent.prototype.ACTION_SEND_MULTIPLE = "android.intent.action.SEND_MULTIPLE"; - WebIntent.prototype.ACTION_VIEW= "android.intent.action.VIEW"; - WebIntent.prototype.EXTRA_TEXT = "android.intent.extra.TEXT"; - WebIntent.prototype.EXTRA_SUBJECT = "android.intent.extra.SUBJECT"; - WebIntent.prototype.EXTRA_STREAM = "android.intent.extra.STREAM"; - WebIntent.prototype.EXTRA_EMAIL = "android.intent.extra.EMAIL"; - WebIntent.prototype.ACTION_CALL = "android.intent.action.CALL"; - WebIntent.prototype.ACTION_SENDTO = "android.intent.action.SENDTO"; - - WebIntent.prototype.startActivity = function(params, success, fail) { - return cordova.exec(function(args) { - success(args); - }, function(args) { - fail(args); - }, 'WebIntent', 'startActivity', [params]); - }; - - WebIntent.prototype.hasExtra = function(params, success, fail) { - return cordova.exec(function(args) { - success(args); - }, function(args) { - fail(args); - }, 'WebIntent', 'hasExtra', [params]); - }; - - WebIntent.prototype.getUri = function(success, fail) { - return cordova.exec(function(args) { - success(args); - }, function(args) { - fail(args); - }, 'WebIntent', 'getUri', []); - }; - - WebIntent.prototype.getExtra = function(params, success, fail) { - return cordova.exec(function(args) { - success(args); - }, function(args) { - fail(args); - }, 'WebIntent', 'getExtra', [params]); - }; - - - WebIntent.prototype.onNewIntent = function(callback) { - return cordova.exec(function(args) { - callback(args); - }, function(args) { - }, 'WebIntent', 'onNewIntent', []); - }; - - WebIntent.prototype.sendBroadcast = function(params, success, fail) { - return cordova.exec(function(args) { - success(args); - }, function(args) { - fail(args); - }, 'WebIntent', 'sendBroadcast', [params]); - }; - - WebIntent.prototype.removeExtra = function(params, success, fail) { - return cordova.exec(function(args) { - success(args); - }, function(args) { - fail(args); - }, 'WebIntent', 'removeExtra', [params]); - }; - - window.webintent = new WebIntent(); - - // backwards compatibility - window.plugins = window.plugins || {}; - window.plugins.webintent = window.webintent; -})(window.PhoneGap || window.Cordova || window.cordova); +/** + * cordova Web Intent plugin + * Copyright (c) Boris Smus 2010 + * + */ + (function(cordova){ + var WebIntent = function() { + + }; + + WebIntent.prototype.ACTION_SEND = "android.intent.action.SEND"; + WebIntent.prototype.ACTION_SEND_MULTIPLE = "android.intent.action.SEND_MULTIPLE"; + WebIntent.prototype.ACTION_VIEW= "android.intent.action.VIEW"; + WebIntent.prototype.EXTRA_TEXT = "android.intent.extra.TEXT"; + WebIntent.prototype.EXTRA_SUBJECT = "android.intent.extra.SUBJECT"; + WebIntent.prototype.EXTRA_STREAM = "android.intent.extra.STREAM"; + WebIntent.prototype.EXTRA_EMAIL = "android.intent.extra.EMAIL"; + WebIntent.prototype.ACTION_CALL = "android.intent.action.CALL"; + WebIntent.prototype.ACTION_SENDTO = "android.intent.action.SENDTO"; + + WebIntent.prototype.startActivity = function(params, success, fail) { + return cordova.exec(function(args) { + success(args); + }, function(args) { + fail(args); + }, 'WebIntent', 'startActivity', [params]); + }; + + WebIntent.prototype.hasExtra = function(params, success, fail) { + return cordova.exec(function(args) { + success(args); + }, function(args) { + fail(args); + }, 'WebIntent', 'hasExtra', [params]); + }; + + WebIntent.prototype.getUri = function(success, fail) { + return cordova.exec(function(args) { + success(args); + }, function(args) { + fail(args); + }, 'WebIntent', 'getUri', []); + }; + + WebIntent.prototype.getExtra = function(params, success, fail) { + return cordova.exec(function(args) { + success(args); + }, function(args) { + fail(args); + }, 'WebIntent', 'getExtra', [params]); + }; + + + WebIntent.prototype.onNewIntent = function(callback) { + return cordova.exec(function(args) { + callback(args); + }, function(args) { + }, 'WebIntent', 'onNewIntent', []); + }; + + WebIntent.prototype.sendBroadcast = function(params, success, fail) { + return cordova.exec(function(args) { + success(args); + }, function(args) { + fail(args); + }, 'WebIntent', 'sendBroadcast', [params]); + }; + + WebIntent.prototype.removeExtra = function(params, success, fail) { + return cordova.exec(function(args) { + success(args); + }, function(args) { + fail(args); + }, 'WebIntent', 'removeExtra', [params]); + }; + + window.webintent = new WebIntent(); + + // backwards compatibility + window.plugins = window.plugins || {}; + window.plugins.webintent = window.webintent; +})(window.PhoneGap || window.Cordova || window.cordova);