update plugin

add package, type, intent date uri
This commit is contained in:
Roman
2015-12-07 16:37:35 +03:00
parent eda045ab92
commit f155d6389a
6 changed files with 58 additions and 242 deletions
+2 -2
View File
@@ -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"
+1 -1
View File
@@ -2,7 +2,7 @@
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
id="com.lampa.startapp"
version="0.0.4">
version="0.0.5">
<name>startApp</name>
<description>Phonegap 3 plugin for check or launch other application in android device.</description>
+55 -9
View File
@@ -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());
}
-23
View File
@@ -1,23 +0,0 @@
<!DOCTYPE html>
<!--
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
-->
<html>
<head>
<meta name="viewport" content="width=device-width,height=device-height,user-scalable=no,initial-scale=1.0" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>com.lampa.startApp test</title>
<link rel="stylesheet" href="master.css" type="text/css" media="screen" title="no title" charset="utf-8">
<script type="text/javascript" charset="utf-8" src="cordova-incl.js"></script>
<script type="text/javascript" charset="utf-8" src="startApp.js"></script>
<script type="text/javascript" charset="utf-8" src="main.js"></script>
</head>
<body onload="init();" id="stage" class="theme">
</body>
</html>
-43
View File
@@ -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);
});
}
-164
View File
@@ -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%;
}