From 00508d1462937ee11f80f17044391c1be63907dd Mon Sep 17 00:00:00 2001 From: Paul Em Date: Sun, 19 Oct 2014 20:31:21 +0200 Subject: [PATCH 01/10] added gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..be98a19 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea +.tmp \ No newline at end of file From f7308c2dfa17ffac2baed7253904ead50d3dd2ca Mon Sep 17 00:00:00 2001 From: Paul Em Date: Sun, 19 Oct 2014 21:20:52 +0200 Subject: [PATCH 02/10] added possibility for custom icon --- src/android/ShortcutPlugin.java | 143 +++++++++++++++++++------------- www/ShortcutPlugin.js | 60 ++++++++------ 2 files changed, 121 insertions(+), 82 deletions(-) diff --git a/src/android/ShortcutPlugin.java b/src/android/ShortcutPlugin.java index 287f7f4..6a47ca6 100644 --- a/src/android/ShortcutPlugin.java +++ b/src/android/ShortcutPlugin.java @@ -9,67 +9,94 @@ import org.json.JSONException; import android.content.Intent; import android.content.Context; -import android.os.Parcelable; +import android.os.Parcelable; import android.content.pm.ResolveInfo; import android.content.pm.PackageManager; public class ShortcutPlugin extends CordovaPlugin { - public static final String ACTION_ADD_SHORTCUT = "addShortcut"; - public static final String ACTION_DEL_SHORTCUT = "delShortcut"; - - @Override - public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { - - try { - if (ACTION_ADD_SHORTCUT.equals(action)) { - - //Get params - JSONObject arg_object = args.getJSONObject(0); - - Context context=this.cordova.getActivity().getApplicationContext(); - PackageManager pm = context.getPackageManager(); - - Intent i = new Intent(); - i.setClassName(this.cordova.getActivity().getPackageName(), this.cordova.getActivity().getClass().getName()); - i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - - Intent shortcutintent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT"); - shortcutintent.putExtra("duplicate", false); - shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_NAME, arg_object.getString("shortcuttext")); - - //Get Icon - ResolveInfo ri = pm.resolveActivity(i, 0); - int iconId = ri.activityInfo.applicationInfo.icon; - Parcelable icon = Intent.ShortcutIconResource.fromContext(context, iconId); - - shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon); - shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, i); - context.sendBroadcast(shortcutintent); - - callbackContext.success(); - return true; - } else if (ACTION_DEL_SHORTCUT.equals(action)) { - JSONObject arg_object = args.getJSONObject(0); - Context context=this.cordova.getActivity().getApplicationContext(); - - Intent i = new Intent(); - i.setClassName(this.cordova.getActivity().getPackageName(), this.cordova.getActivity().getClass().getName()); - i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - - Intent shortcutintent = new Intent("com.android.launcher.action.UNINSTALL_SHORTCUT"); - shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_NAME, arg_object.getString("shortcuttext")); - shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, i); - context.sendBroadcast(shortcutintent); - callbackContext.success(); - } - callbackContext.error("Invalid action"); - return false; - } catch(Exception e) { - System.err.println("Exception: " + e.getMessage()); - callbackContext.error(e.getMessage()); - return false; - } + public static final String ACTION_ADD_SHORTCUT = "addShortcut"; + public static final String ACTION_DEL_SHORTCUT = "delShortcut"; + + @Override + public boolean execute(String action, JSONArray args, + CallbackContext callbackContext) throws JSONException { + + try { + if (ACTION_ADD_SHORTCUT.equals(action)) { + + // Get params + JSONObject arg_object = args.getJSONObject(0); + + // set param defaults + String shortcuttext = arg_object.getString("shortcuttext"); + String icon = arg_object.getString("icon"); + + + Context context = this.cordova.getActivity() + .getApplicationContext(); + PackageManager pm = context.getPackageManager(); + + Intent i = new Intent(); + i.setClassName(this.cordova.getActivity().getPackageName(), + this.cordova.getActivity().getClass().getName()); + i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + + Intent shortcutintent = new Intent( + "com.android.launcher.action.INSTALL_SHORTCUT"); + shortcutintent.putExtra("duplicate", false); + shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_NAME, + arg_object.getString("shortcuttext")); + + // Get Icon + if(isNull(icon)){ + ResolveInfo ri = pm.resolveActivity(i, 0); + int iconId = ri.activityInfo.applicationInfo.icon; + Parcelable icon = Intent.ShortcutIconResource.fromContext( + context, iconId); + shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon); + } else { + Drawable iconDrawable = decodeBase64(icon); + BitmapDrawable bd = (BitmapDrawable) iconDrawable; + shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_ICON, bd.getBitmap()); + } + + shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, i); + context.sendBroadcast(shortcutintent); + + callbackContext.success(); + return true; + } else if (ACTION_DEL_SHORTCUT.equals(action)) { + JSONObject arg_object = args.getJSONObject(0); + Context context = this.cordova.getActivity() + .getApplicationContext(); + + Intent i = new Intent(); + i.setClassName(this.cordova.getActivity().getPackageName(), + this.cordova.getActivity().getClass().getName()); + i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + + Intent shortcutintent = new Intent( + "com.android.launcher.action.UNINSTALL_SHORTCUT"); + shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_NAME, + arg_object.getString("shortcuttext")); + shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, i); + context.sendBroadcast(shortcutintent); + callbackContext.success(); + } + callbackContext.error("Invalid action"); + return false; + } catch (Exception e) { + System.err.println("Exception: " + e.getMessage()); + callbackContext.error(e.getMessage()); + return false; + } + } + + private static Bitmap decodeBase64(String input) + { + byte[] decodedByte = Base64.decode(input, 0); + return BitmapFactory.decodeByteArray(decodedByte, 0, decodedByte.length); } } diff --git a/www/ShortcutPlugin.js b/www/ShortcutPlugin.js index fc222aa..1102819 100644 --- a/www/ShortcutPlugin.js +++ b/www/ShortcutPlugin.js @@ -1,33 +1,45 @@ //Copyright 2013 Jorge Cisneros jorgecis@gmail.com -var ShortcutPlugin = function() {}; +var ShortcutPlugin = function () { +}; + +ShortcutPlugin.prototype.CreateShortcut = function (data, successCallback, errorCallback) { + + // to provide backwards compatibility + if (typeof data === 'String') { + data = { + shortcuttext: data + }; + } + + if (typeof data !== 'Object' || typeof data.shortcuttext !== 'String') { + errorCallback('required shortcuttext is not set or not a string'); + return; + } -ShortcutPlugin.prototype.CreateShortcut = function (shortcut_text, successCallback, errorCallback) { - cordova.exec( - successCallback, - errorCallback, - 'ShortcutPlugin', - 'addShortcut', - [{ - "shortcuttext": shortcut_text - }] - ); + cordova.exec( + successCallback, + errorCallback, + 'ShortcutPlugin', + 'addShortcut', + [data] + ); }; -ShortcutPlugin.prototype.RemoveShortcut = function(shortcut_text, successCallback, errorCallback) { - cordova.exec( - successCallback, - errorCallback, - 'ShortcutPlugin', - 'delShortcut', - [{ - "shortcuttext": shortcut_text - }] - ); +ShortcutPlugin.prototype.RemoveShortcut = function (shortcut_text, successCallback, errorCallback) { + cordova.exec( + successCallback, + errorCallback, + 'ShortcutPlugin', + 'delShortcut', + [{ + "shortcuttext": shortcut_text + }] + ); }; -if(!window.plugins) { - window.plugins = {}; +if (!window.plugins) { + window.plugins = {}; } if (!window.plugins.Shortcut) { - window.plugins.Shortcut = new ShortcutPlugin(); + window.plugins.Shortcut = new ShortcutPlugin(); } From 4a94db2f0cda1e75893d6b0dd9f798103223dedc Mon Sep 17 00:00:00 2001 From: Paul Em Date: Sun, 19 Oct 2014 21:54:12 +0200 Subject: [PATCH 03/10] fixes java compile issues --- src/android/ShortcutPlugin.java | 16 ++++++++++------ www/ShortcutPlugin.js | 4 ++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/android/ShortcutPlugin.java b/src/android/ShortcutPlugin.java index 6a47ca6..b283733 100644 --- a/src/android/ShortcutPlugin.java +++ b/src/android/ShortcutPlugin.java @@ -7,6 +7,10 @@ import org.json.JSONObject; import org.json.JSONArray; import org.json.JSONException; +import android.util.Base64; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.graphics.drawable.*; import android.content.Intent; import android.content.Context; import android.os.Parcelable; @@ -29,8 +33,10 @@ public boolean execute(String action, JSONArray args, // set param defaults String shortcuttext = arg_object.getString("shortcuttext"); - String icon = arg_object.getString("icon"); - + String iconBase64 = null; + if( arg_object.has("icon")){ + iconBase64 = arg_object.getString("icon"); + } Context context = this.cordova.getActivity() .getApplicationContext(); @@ -49,16 +55,14 @@ public boolean execute(String action, JSONArray args, arg_object.getString("shortcuttext")); // Get Icon - if(isNull(icon)){ + if(iconBase64 == null){ ResolveInfo ri = pm.resolveActivity(i, 0); int iconId = ri.activityInfo.applicationInfo.icon; Parcelable icon = Intent.ShortcutIconResource.fromContext( context, iconId); shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon); } else { - Drawable iconDrawable = decodeBase64(icon); - BitmapDrawable bd = (BitmapDrawable) iconDrawable; - shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_ICON, bd.getBitmap()); + shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_ICON, decodeBase64(iconBase64)); } shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, i); diff --git a/www/ShortcutPlugin.js b/www/ShortcutPlugin.js index 1102819..792a650 100644 --- a/www/ShortcutPlugin.js +++ b/www/ShortcutPlugin.js @@ -6,13 +6,13 @@ var ShortcutPlugin = function () { ShortcutPlugin.prototype.CreateShortcut = function (data, successCallback, errorCallback) { // to provide backwards compatibility - if (typeof data === 'String') { + if (typeof data === 'string') { data = { shortcuttext: data }; } - if (typeof data !== 'Object' || typeof data.shortcuttext !== 'String') { + if (typeof data !== 'object' || typeof data.shortcuttext !== 'string') { errorCallback('required shortcuttext is not set or not a string'); return; } From daf5b983e94e5e2dc31e54a1a11d53a4c43428c8 Mon Sep 17 00:00:00 2001 From: Paul Em Date: Mon, 20 Oct 2014 02:07:40 +0200 Subject: [PATCH 04/10] fixes a few issues - icons work! --- src/android/ShortcutPlugin.java | 7 +++++-- www/ShortcutPlugin.js | 6 +++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/android/ShortcutPlugin.java b/src/android/ShortcutPlugin.java index b283733..cd426e8 100644 --- a/src/android/ShortcutPlugin.java +++ b/src/android/ShortcutPlugin.java @@ -32,7 +32,7 @@ public boolean execute(String action, JSONArray args, JSONObject arg_object = args.getJSONObject(0); // set param defaults - String shortcuttext = arg_object.getString("shortcuttext"); + String shortcuttext = arg_object.getString("text"); String iconBase64 = null; if( arg_object.has("icon")){ iconBase64 = arg_object.getString("icon"); @@ -52,7 +52,7 @@ public boolean execute(String action, JSONArray args, "com.android.launcher.action.INSTALL_SHORTCUT"); shortcutintent.putExtra("duplicate", false); shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_NAME, - arg_object.getString("shortcuttext")); + shortcuttext); // Get Icon if(iconBase64 == null){ @@ -62,6 +62,9 @@ public boolean execute(String action, JSONArray args, context, iconId); shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon); } else { + //Bitmap bmpIcon = decodeBase64(iconBase64); + //Bitmap scaledBitmap = Bitmap.createScaledBitmap(bmpIcon, 128, 128, true); + //shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_ICON, scaledBitmap); shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_ICON, decodeBase64(iconBase64)); } diff --git a/www/ShortcutPlugin.js b/www/ShortcutPlugin.js index 792a650..34f7fee 100644 --- a/www/ShortcutPlugin.js +++ b/www/ShortcutPlugin.js @@ -8,12 +8,12 @@ ShortcutPlugin.prototype.CreateShortcut = function (data, successCallback, error // to provide backwards compatibility if (typeof data === 'string') { data = { - shortcuttext: data + text: data }; } - if (typeof data !== 'object' || typeof data.shortcuttext !== 'string') { - errorCallback('required shortcuttext is not set or not a string'); + if (typeof data !== 'object' || typeof data.text !== 'string') { + errorCallback('required text is not set or not a string'); return; } From 292b5ba1f8f67c15c558c64a94ae234e79be79e1 Mon Sep 17 00:00:00 2001 From: Paul Em Date: Mon, 20 Oct 2014 02:10:06 +0200 Subject: [PATCH 05/10] updated description --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 66e93b5..8ace8fe 100644 --- a/README.md +++ b/README.md @@ -60,4 +60,14 @@ Note: This plugin is for phonegap 3.x ``` + If you want to create a custom icon you can pass an object +``` + +``` + [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/jorgecis/shortcutplugin/trend.png)](https://bitdeli.com/free "Bitdeli Badge") From 4b020377a680e5093b6f8e9d5e3e2a6767bb6c5e Mon Sep 17 00:00:00 2001 From: Paul Em Date: Mon, 20 Oct 2014 21:02:45 +0200 Subject: [PATCH 06/10] added custom activity --- src/android/ShortcutPlugin.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/android/ShortcutPlugin.java b/src/android/ShortcutPlugin.java index cd426e8..074b5fc 100644 --- a/src/android/ShortcutPlugin.java +++ b/src/android/ShortcutPlugin.java @@ -2,6 +2,7 @@ package com.plugins.shortcut; +import com.w3pin.browser.Browser; import org.apache.cordova.CallbackContext; import org.apache.cordova.CordovaPlugin; import org.json.JSONObject; @@ -34,17 +35,30 @@ public boolean execute(String action, JSONArray args, // set param defaults String shortcuttext = arg_object.getString("text"); String iconBase64 = null; + String activityClass = null; + String activityPackage = null; if( arg_object.has("icon")){ iconBase64 = arg_object.getString("icon"); } + if( arg_object.has("activityClass") & arg_object.has("activityPackage")){ + activityClass = arg_object.getString("activityClass"); + activityPackage = arg_object.getString("activityPackage"); + } + + Context context = this.cordova.getActivity() .getApplicationContext(); PackageManager pm = context.getPackageManager(); Intent i = new Intent(); - i.setClassName(this.cordova.getActivity().getPackageName(), - this.cordova.getActivity().getClass().getName()); + if(activityClass == null){ + i.setClassName(this.cordova.getActivity().getPackageName(), + this.cordova.getActivity().getClass().getName()); + } else { + i.setClassName(activityPackage,activityClass); + } + i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); From a5a6d65b8001ab3e92d7bd5784958fd0be23664e Mon Sep 17 00:00:00 2001 From: Paul Em Date: Mon, 20 Oct 2014 21:21:13 +0200 Subject: [PATCH 07/10] removed unnecessary import --- src/android/ShortcutPlugin.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/android/ShortcutPlugin.java b/src/android/ShortcutPlugin.java index 074b5fc..b896452 100644 --- a/src/android/ShortcutPlugin.java +++ b/src/android/ShortcutPlugin.java @@ -2,7 +2,6 @@ package com.plugins.shortcut; -import com.w3pin.browser.Browser; import org.apache.cordova.CallbackContext; import org.apache.cordova.CordovaPlugin; import org.json.JSONObject; From 793c80b54ff4930c4b6c1d98c786ad157015f3d8 Mon Sep 17 00:00:00 2001 From: Paul Em Date: Mon, 20 Oct 2014 22:55:43 +0200 Subject: [PATCH 08/10] reformat code --- src/android/ShortcutPlugin.java | 192 ++++++++++++++++---------------- 1 file changed, 96 insertions(+), 96 deletions(-) diff --git a/src/android/ShortcutPlugin.java b/src/android/ShortcutPlugin.java index b896452..c703557 100644 --- a/src/android/ShortcutPlugin.java +++ b/src/android/ShortcutPlugin.java @@ -18,104 +18,104 @@ import android.content.pm.PackageManager; public class ShortcutPlugin extends CordovaPlugin { - public static final String ACTION_ADD_SHORTCUT = "addShortcut"; - public static final String ACTION_DEL_SHORTCUT = "delShortcut"; - - @Override - public boolean execute(String action, JSONArray args, - CallbackContext callbackContext) throws JSONException { - - try { - if (ACTION_ADD_SHORTCUT.equals(action)) { - - // Get params - JSONObject arg_object = args.getJSONObject(0); - - // set param defaults - String shortcuttext = arg_object.getString("text"); - String iconBase64 = null; - String activityClass = null; - String activityPackage = null; - if( arg_object.has("icon")){ - iconBase64 = arg_object.getString("icon"); + public static final String ACTION_ADD_SHORTCUT = "addShortcut"; + public static final String ACTION_DEL_SHORTCUT = "delShortcut"; + + @Override + public boolean execute(String action, JSONArray args, + CallbackContext callbackContext) throws JSONException { + + try { + if (ACTION_ADD_SHORTCUT.equals(action)) { + + // Get params + JSONObject arg_object = args.getJSONObject(0); + + // set param defaults + String shortcuttext = arg_object.getString("text"); + String iconBase64 = null; + String activityClass = null; + String activityPackage = null; + if (arg_object.has("icon")) { + iconBase64 = arg_object.getString("icon"); + } + + if (arg_object.has("activityClass") & arg_object.has("activityPackage")) { + activityClass = arg_object.getString("activityClass"); + activityPackage = arg_object.getString("activityPackage"); + } + + + Context context = this.cordova.getActivity() + .getApplicationContext(); + PackageManager pm = context.getPackageManager(); + + Intent i = new Intent(); + if (activityClass == null) { + i.setClassName(this.cordova.getActivity().getPackageName(), + this.cordova.getActivity().getClass().getName()); + } else { + i.setClassName(activityPackage, activityClass); + } + + i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + i.putExtra(Intent.EXTRA_SUBJECT, "ShortcutPluginLaunch"); + + Intent shortcutintent = new Intent( + "com.android.launcher.action.INSTALL_SHORTCUT"); + shortcutintent.putExtra("duplicate", false); + shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_NAME, + shortcuttext); + + // Get Icon + if (iconBase64 == null) { + ResolveInfo ri = pm.resolveActivity(i, 0); + int iconId = ri.activityInfo.applicationInfo.icon; + Parcelable icon = Intent.ShortcutIconResource.fromContext( + context, iconId); + shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon); + } else { + //Bitmap bmpIcon = decodeBase64(iconBase64); + //Bitmap scaledBitmap = Bitmap.createScaledBitmap(bmpIcon, 128, 128, true); + //shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_ICON, scaledBitmap); + shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_ICON, decodeBase64(iconBase64)); + } + + shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, i); + context.sendBroadcast(shortcutintent); + + callbackContext.success(); + return true; + } else if (ACTION_DEL_SHORTCUT.equals(action)) { + JSONObject arg_object = args.getJSONObject(0); + Context context = this.cordova.getActivity() + .getApplicationContext(); + + Intent i = new Intent(); + i.setClassName(this.cordova.getActivity().getPackageName(), + this.cordova.getActivity().getClass().getName()); + i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + + Intent shortcutintent = new Intent( + "com.android.launcher.action.UNINSTALL_SHORTCUT"); + shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_NAME, + arg_object.getString("shortcuttext")); + shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, i); + context.sendBroadcast(shortcutintent); + callbackContext.success(); + } + callbackContext.error("Invalid action"); + return false; + } catch (Exception e) { + System.err.println("Exception: " + e.getMessage()); + callbackContext.error(e.getMessage()); + return false; } + } - if( arg_object.has("activityClass") & arg_object.has("activityPackage")){ - activityClass = arg_object.getString("activityClass"); - activityPackage = arg_object.getString("activityPackage"); - } - - - Context context = this.cordova.getActivity() - .getApplicationContext(); - PackageManager pm = context.getPackageManager(); - - Intent i = new Intent(); - if(activityClass == null){ - i.setClassName(this.cordova.getActivity().getPackageName(), - this.cordova.getActivity().getClass().getName()); - } else { - i.setClassName(activityPackage,activityClass); - } - - i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - - Intent shortcutintent = new Intent( - "com.android.launcher.action.INSTALL_SHORTCUT"); - shortcutintent.putExtra("duplicate", false); - shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_NAME, - shortcuttext); - - // Get Icon - if(iconBase64 == null){ - ResolveInfo ri = pm.resolveActivity(i, 0); - int iconId = ri.activityInfo.applicationInfo.icon; - Parcelable icon = Intent.ShortcutIconResource.fromContext( - context, iconId); - shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon); - } else { - //Bitmap bmpIcon = decodeBase64(iconBase64); - //Bitmap scaledBitmap = Bitmap.createScaledBitmap(bmpIcon, 128, 128, true); - //shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_ICON, scaledBitmap); - shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_ICON, decodeBase64(iconBase64)); - } - - shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, i); - context.sendBroadcast(shortcutintent); - - callbackContext.success(); - return true; - } else if (ACTION_DEL_SHORTCUT.equals(action)) { - JSONObject arg_object = args.getJSONObject(0); - Context context = this.cordova.getActivity() - .getApplicationContext(); - - Intent i = new Intent(); - i.setClassName(this.cordova.getActivity().getPackageName(), - this.cordova.getActivity().getClass().getName()); - i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - - Intent shortcutintent = new Intent( - "com.android.launcher.action.UNINSTALL_SHORTCUT"); - shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_NAME, - arg_object.getString("shortcuttext")); - shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, i); - context.sendBroadcast(shortcutintent); - callbackContext.success(); - } - callbackContext.error("Invalid action"); - return false; - } catch (Exception e) { - System.err.println("Exception: " + e.getMessage()); - callbackContext.error(e.getMessage()); - return false; - } - } - - private static Bitmap decodeBase64(String input) - { + private static Bitmap decodeBase64(String input) { byte[] decodedByte = Base64.decode(input, 0); return BitmapFactory.decodeByteArray(decodedByte, 0, decodedByte.length); } From bff47dab1be36198eb8265183b3afae7a37a38f2 Mon Sep 17 00:00:00 2001 From: Paul Em Date: Mon, 20 Oct 2014 22:56:32 +0200 Subject: [PATCH 09/10] version change --- plugin.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.xml b/plugin.xml index 8738f01..3d0c5ea 100644 --- a/plugin.xml +++ b/plugin.xml @@ -2,7 +2,7 @@ + version="0.0.2"> Home Shortcuts From 7a03bf34da426ad201747ad2333e76a6a30df06f Mon Sep 17 00:00:00 2001 From: Paul Em Date: Mon, 20 Oct 2014 23:43:51 +0200 Subject: [PATCH 10/10] added extraSubject to available api --- src/android/ShortcutPlugin.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/android/ShortcutPlugin.java b/src/android/ShortcutPlugin.java index c703557..ce3a0dd 100644 --- a/src/android/ShortcutPlugin.java +++ b/src/android/ShortcutPlugin.java @@ -36,6 +36,8 @@ public boolean execute(String action, JSONArray args, String iconBase64 = null; String activityClass = null; String activityPackage = null; + String extraSubject = null; + if (arg_object.has("icon")) { iconBase64 = arg_object.getString("icon"); } @@ -45,6 +47,9 @@ public boolean execute(String action, JSONArray args, activityPackage = arg_object.getString("activityPackage"); } + if (arg_object.has("extraSubject")) { + extraSubject = arg_object.getString("extraSubject"); + } Context context = this.cordova.getActivity() .getApplicationContext(); @@ -60,7 +65,10 @@ public boolean execute(String action, JSONArray args, i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - i.putExtra(Intent.EXTRA_SUBJECT, "ShortcutPluginLaunch"); + + if(extraSubject != null){ + i.putExtra(Intent.EXTRA_SUBJECT, extraSubject); + } Intent shortcutintent = new Intent( "com.android.launcher.action.INSTALL_SHORTCUT");