From f155d6389a9924cd3a5ea982bd4f0bebfffc75d8 Mon Sep 17 00:00:00 2001 From: Roman Date: Mon, 7 Dec 2015 16:37:35 +0300 Subject: [PATCH] update plugin add package, type, intent date uri --- package.json | 4 +- plugin.xml | 2 +- src/android/startApp.java | 64 ++++++++++++--- test/index.html | 23 ------ test/main.js | 43 ---------- test/master.css | 164 -------------------------------------- 6 files changed, 58 insertions(+), 242 deletions(-) delete mode 100644 test/index.html delete mode 100644 test/main.js delete mode 100644 test/master.css diff --git a/package.json b/package.json index 87ef176..5396e42 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordova-plugin-startapp", - "version": "0.0.4", + "version": "0.0.5", "description": "Phonegap 3 plugin for check or launch other application in android device.", "cordova": { "id": "com.lampa.startapp", @@ -21,7 +21,7 @@ "cordova-android", "cordova-ios" ], - "author": "", + "author": "lampaa", "license": "MIT", "bugs": { "url": "https://github.com/lampaa/com.lampa.startapp/issues" diff --git a/plugin.xml b/plugin.xml index c37bac8..039431e 100644 --- a/plugin.xml +++ b/plugin.xml @@ -2,7 +2,7 @@ + version="0.0.5"> startApp Phonegap 3 plugin for check or launch other application in android device. diff --git a/src/android/startApp.java b/src/android/startApp.java index 234bb56..95565e4 100644 --- a/src/android/startApp.java +++ b/src/android/startApp.java @@ -57,14 +57,21 @@ public class startApp extends CordovaPlugin { */ public void start(JSONArray args, CallbackContext callback) { - String com_name = null; - String activity = null; Intent LaunchIntent; + String com_name = null; + + String activity = null; + String spackage = null; + String intenuri = null; + try { if (args.get(0) instanceof JSONArray) { com_name = args.getJSONArray(0).getString(0); - activity = args.getJSONArray(0).getString(1); + activity = args.getJSONArray(0).getString(1); + spackage = args.getJSONArray(0).getString(2); + intetype = args.getJSONArray(0).getString(3); + intenuri = args.getJSONArray(0).getString(4); } else { com_name = args.getString(0); @@ -75,12 +82,20 @@ public class startApp extends CordovaPlugin { */ if(activity != null) { if(com_name.equals("action")) { - // sample: android.intent.action.VIEW - if(activity.indexOf(".") > 0) { - LaunchIntent = new Intent(activity); + /** + * . < 0: VIEW + * . >= 0: android.intent.action.VIEW + */ + if(activity.indexOf(".") < 0) { + activity = "android.intent.action." + activity; + } + + // if uri exists + if(intenuri != null) { + LaunchIntent = new Intent(activity, Uri.parse(intenuri)); } else { - LaunchIntent = new Intent("android.intent.action." + activity); + LaunchIntent = new Intent(activity); } } else { @@ -92,6 +107,20 @@ public class startApp extends CordovaPlugin { LaunchIntent = this.cordova.getActivity().getPackageManager().getLaunchIntentForPackage(com_name); } + /** + * setPackage, http://developer.android.com/intl/ru/reference/android/content/Intent.html#setPackage(java.lang.String) + */ + if(spackage != null) { + LaunchIntent.setPackage(spackage); + } + + /** + * setType, http://developer.android.com/intl/ru/reference/android/content/Intent.html#setType(java.lang.String) + */ + if(intetype != null) { + LaunchIntent.setType(intetype); + } + /** * put arguments */ @@ -122,6 +151,9 @@ public class startApp extends CordovaPlugin { } } + /** + * start activity + */ this.cordova.getActivity().startActivity(LaunchIntent); callback.success(); @@ -138,8 +170,22 @@ public class startApp extends CordovaPlugin { public void check(String component, CallbackContext callback) { PackageManager pm = this.cordova.getActivity().getApplicationContext().getPackageManager(); try { - pm.getPackageInfo(component, PackageManager.GET_ACTIVITIES); - callback.success(); + /** + * get package info + */ + PackageInfo PackInfo = pm.getPackageInfo(component, PackageManager.GET_ACTIVITIES); + + /** + * create json object + */ + JSONObject info = new JSONObject(); + + info.put("versionName", info.versionName); + info.put("packageName", info.packageName); + info.put("versionCode", info.versionCode); + info.put("applicationInfo", info.applicationInfo); + + callback.success(info); } catch (Exception e) { callback.error(e.toString()); } diff --git a/test/index.html b/test/index.html deleted file mode 100644 index adac768..0000000 --- a/test/index.html +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - com.lampa.startApp test - - - - - - - - diff --git a/test/main.js b/test/main.js deleted file mode 100644 index c1a153e..0000000 --- a/test/main.js +++ /dev/null @@ -1,43 +0,0 @@ -/** - com.lampa.startapp - https://github.com/lampaa/com.lampa.startapp - - Phonegap 3 plugin for check or launch other application in android device (iOS support). - bug tracker: https://github.com/lampaa/org.apache.cordova.startapp/issues -*/ -function init() { - /** - * check the application is installed - */ - navigator.startApp.check('com.teaway.teamenu', function(message) { /* success */ - console.log(message); // => OK - }, - function(error) { /* error */ - console.log('47', error); - }); - - /** - * start application without parameters - */ - navigator.startApp.start('com.teaway.teamenu', function(message) { /* success */ - console.log(message); // => OK - }, - function(error) { /* error */ - console.log('47', error); - }); - - /** - * start application with parameters - */ - navigator.startApp.start([ - 'com.teaway.teamenu', // applucation - 'com.teaway.teamenu.MainActivity', // activity - 'product_id', // key - '102' // value - ], function(message) { /* success */ - console.log(message); // => OK - }, - function(error) { /* error */ - console.log('47', error); - }); -} diff --git a/test/master.css b/test/master.css deleted file mode 100644 index e93c937..0000000 --- a/test/master.css +++ /dev/null @@ -1,164 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * -*/ - - body { - background:#222 none repeat scroll 0 0; - color:#666; - font-family:Helvetica; - font-size:72%; - line-height:1.5em; - margin:0; - border-top:1px solid #393939; - } - - #info{ - background:#ffa; - border: 1px solid #ffd324; - -webkit-border-radius: 5px; - border-radius: 5px; - clear:both; - margin:15px 6px 0; - min-width:295px; - max-width:97%; - padding:4px 0px 2px 10px; - word-wrap:break-word; - margin-bottom:10px; - display:inline-block; - min-height: 160px; - max-height: 300px; - overflow: auto; - -webkit-overflow-scrolling: touch; - } - - #info > h4{ - font-size:.95em; - margin:5px 0; - } - - #stage.theme{ - padding-top:3px; - } - - /* Definition List */ - #stage.theme > dl{ - padding-top:10px; - clear:both; - margin:0; - list-style-type:none; - padding-left:10px; - overflow:auto; - } - - #stage.theme > dl > dt{ - font-weight:bold; - float:left; - margin-left:5px; - } - - #stage.theme > dl > dd{ - width:45px; - float:left; - color:#a87; - font-weight:bold; - } - - /* Content Styling */ - #stage.theme > h1, #stage.theme > h2, #stage.theme > p{ - margin:1em 0 .5em 13px; - } - - #stage.theme > h1{ - color:#eee; - font-size:1.6em; - text-align:center; - margin:0; - margin-top:15px; - padding:0; - } - - #stage.theme > h2{ - clear:both; - margin:0; - padding:3px; - font-size:1em; - text-align:center; - } - - /* Stage Buttons */ - #stage.theme .btn{ - border: 1px solid #555; - -webkit-border-radius: 5px; - border-radius: 5px; - text-align:center; - display:inline-block; - background:#444; - width:150px; - color:#9ab; - font-size:1.1em; - text-decoration:none; - padding:1.2em 0; - margin:3px 0px 3px 5px; - } - - #stage.theme .large{ - width:308px; - padding:1.2em 0; - } - - #stage.theme .wide{ - width:100%; - padding:1.2em 0; - } - - #stage.theme .backBtn{ - border: 1px solid #555; - -webkit-border-radius: 5px; - border-radius: 5px; - text-align:center; - display:block; - float:right; - background:#666; - width:75px; - color:#9ab; - font-size:1.1em; - text-decoration:none; - padding:1.2em 0; - margin:3px 5px 3px 5px; - } - - #stage.theme .input{ - border: 1px solid #555; - -webkit-border-radius: 5px; - border-radius: 5px; - text-align:center; - display:block; - float:light; - background:#888; - color:#9cd; - font-size:1.1em; - text-decoration:none; - padding:1.2em 0; - margin:3px 0px 3px 5px; - } - - #stage.theme .numeric{ - width:100%; - }