From 555e76e5c64e4824f133103ed3cd1d0fc0acd934 Mon Sep 17 00:00:00 2001 From: lampaa Date: Mon, 30 May 2016 14:43:11 +0300 Subject: [PATCH 1/4] Create HISTORY.md --- HISTORY.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 HISTORY.md diff --git a/HISTORY.md b/HISTORY.md new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/HISTORY.md @@ -0,0 +1 @@ + From c1ed81dad49578acd88023f4c3984074307f2b6b Mon Sep 17 00:00:00 2001 From: lampaa Date: Mon, 30 May 2016 14:43:37 +0300 Subject: [PATCH 2/4] Update MANUALLY_INSTALL.md --- MANUALLY_INSTALL.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MANUALLY_INSTALL.md b/MANUALLY_INSTALL.md index 570bab9..b135297 100644 --- a/MANUALLY_INSTALL.md +++ b/MANUALLY_INSTALL.md @@ -9,7 +9,7 @@ Add to ```/my-app/platforms/android/res/xml/config.xml```: Add to ```/my-app/platforms/android/assets/www/cordova_plugins.js```: ```javascript { - "file": "plugins/com.lampa.startapp/www/startApp.js", + "file": "plugins/com.lampa.startapp/www/startApp.manually.js", "id": "com.lampa.startapp", "merges": [ "startApp" From 3c869f7730d6c9d682d0fcf465428bd6417b9d3b Mon Sep 17 00:00:00 2001 From: Roman Date: Mon, 30 May 2016 16:01:54 +0300 Subject: [PATCH 3/4] updates --- src/android/startApp.java | 55 ++++++++++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 12 deletions(-) diff --git a/src/android/startApp.java b/src/android/startApp.java index 8624663..ac2d5df 100644 --- a/src/android/startApp.java +++ b/src/android/startApp.java @@ -30,6 +30,7 @@ public class startApp extends CordovaPlugin { public static final String TAG = "startApp"; public startApp() { } + private boolean NO_PARSE_INTENT_VALS = false; /** * Executes the request and returns PluginResult. @@ -37,7 +38,7 @@ public class startApp extends CordovaPlugin { * @param action The action to execute. * @param args JSONArray of arguments for the plugin. * @param callbackContext The callback context used when calling back into JavaScript. - * @return True when the action was valid, false otherwise. + * @return Always return true. */ public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { if (action.equals("start")) { @@ -56,9 +57,7 @@ public class startApp extends CordovaPlugin { return true; } - //-------------------------------------------------------------------------- - // LOCAL METHODS - //-------------------------------------------------------------------------- + /** * startApp */ @@ -76,12 +75,40 @@ public class startApp extends CordovaPlugin { int i; try { - - if (args.get(0) instanceof JSONObject) { params = args.getJSONObject(0); + + /** + * disable parsing intent values + */ + if(params.has("no_parse")) { + NO_PARSE_INTENT_VALS = true; + } - LaunchIntent = new Intent(); + /** + * set application + * http://developer.android.com/reference/android/content/Intent.html(java.lang.String) + */ + if(params.has("application")) { + PackageManager manager = cordova.getActivity().getApplicationContext().getPackageManager(); + LaunchIntent = manager.getLaunchIntentForPackage(params.getString("application")); + + if (LaunchIntent == null) { + callback.error("Application \""+ params.getString("application") +"\" not found!"); + return; + } + } + /** + * set application + * http://developer.android.com/reference/android/content/Intent.html (java.lang.String) + */ + else if(params.has("intent")) { + LaunchIntent = new Intent(params.getString("intent")); + } + else { + LaunchIntent = new Intent(); + } + /** * set package @@ -299,14 +326,13 @@ public class startApp extends CordovaPlugin { } /** - * static functions + * functions */ - static String parseExtraName(String extraName) { + private String parseExtraName(String extraName) { String parseIntentExtra = extraName; try { parseIntentExtra = getIntentValueString(extraName); - Log.i(TAG, parseIntentExtra); } catch(NoSuchFieldException e) { parseIntentExtra = extraName; @@ -321,14 +347,19 @@ public class startApp extends CordovaPlugin { return parseIntentExtra; } - static String getIntentValueString(String flag) throws NoSuchFieldException, IllegalAccessException { + private String getIntentValueString(String flag) throws NoSuchFieldException, IllegalAccessException { + + if(NO_PARSE_INTENT_VALS) { + return flag; + } + Field field = Intent.class.getDeclaredField(flag); field.setAccessible(true); return (String) field.get(null); } - static int getIntentValue(String flag) throws NoSuchFieldException, IllegalAccessException { + private int getIntentValue(String flag) throws NoSuchFieldException, IllegalAccessException { Field field = Intent.class.getDeclaredField(flag); field.setAccessible(true); From e482360f05e74a0299b8aa231cd0187014bd0950 Mon Sep 17 00:00:00 2001 From: lampaa Date: Mon, 30 May 2016 16:11:00 +0300 Subject: [PATCH 4/4] Update README.md --- README.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2c582f8..3194c5f 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,9 @@ var sApp = startApp.set({} params [, {} extras]); ``` | Param | Description | Default | Values | | --- | --- | --- | --- | +| intent | [Intent(String action)](https://developer.android.com/reference/android/content/Intent.html#Intent%28java.lang.String%29)) | null | String | +| application | [Intent (Context packageContext)](https://developer.android.com/reference/android/content/Intent.html#Intent%28android.content.Context,%20java.lang.Class%3C?%3E%29) | null | String | +| action | [Intent setAction](http://developer.android.com/reference/android/content/Intent.html#setAction(java.lang.String)) | null | String | | action | [Intent setAction](http://developer.android.com/reference/android/content/Intent.html#setAction(java.lang.String)) | null | String | | category | [Intent addCategory](http://developer.android.com/reference/android/content/Intent.html#addCategory(java.lang.String)) | null | String | | type | [Intent setType](http://developer.android.com/intl/ru/reference/android/content/Intent.html#setType(java.lang.String)) | null | String | @@ -120,10 +123,18 @@ Variable ```field``` is a String. _Set application as only package name_: ```js var sApp = startApp.set({ - "package":"com.application.name" + "application":"com.application.name" }); ``` +_Set application as intent value and flag ([issue](https://github.com/lampaa/com.lampa.startapp/issues/50))_: +```js +var sApp = startApp.set({ + "intent": "com.shazam.android.intent.actions.START_TAGGING", + "flags": ["FLAG_ACTIVITY_NEW_TASK"] +}); +``` + _Set application as package and activity_: ```js var sApp = startApp.set({