mirror of
https://github.com/lampaa/com.lampa.startapp.git
synced 2026-02-15 00:07:54 +08:00
upload new version 0.1.0
added test scripts
This commit is contained in:
23
MANUALLY_INSTALL.md
Normal file
23
MANUALLY_INSTALL.md
Normal file
@@ -0,0 +1,23 @@
|
||||
Manually installation for Android:
|
||||
|
||||
Add to ```/my-app/platforms/android/res/xml/config.xml```:
|
||||
```xml
|
||||
<feature name="startApp">
|
||||
<param name="android-package" value="com.lampa.startapp.startApp" />
|
||||
</feature>
|
||||
```
|
||||
Add to ```/my-app/platforms/android/assets/www/cordova_plugins.js```:
|
||||
```javascript
|
||||
{
|
||||
"file": "plugins/com.lampa.startapp/www/startApp.js",
|
||||
"id": "com.lampa.startapp",
|
||||
"merges": [
|
||||
"navigator.startApp"
|
||||
]
|
||||
}
|
||||
```
|
||||
Add to ```/my-app/platforms/android/assets/www/plugins/com.lampa.startapp/www/``` file:
|
||||
https://github.com/lampaa/com.lampa.startapp/blob/master/www/startApp.js
|
||||
|
||||
Add to ```/my-app/platforms/android/src/com/lampa/startapp/``` file:
|
||||
https://github.com/lampaa/com.lampa.startapp/blob/master/src/android/startApp.java
|
||||
253
README.md
253
README.md
@@ -13,172 +13,207 @@ Delete: ```cordova plugin rm com.lampa.startapp```
|
||||
Delete previos version: ```cordova plugin rm org.apache.cordova.startapp```
|
||||
|
||||
===========================================
|
||||
[Manually installation for Android.](/lampaa/com.lampa.startapp/MANUALLY_INSTALL.md)
|
||||
|
||||
Manually installation for Android:
|
||||
|
||||
Add to ```/my-app/platforms/android/res/xml/config.xml```:
|
||||
```xml
|
||||
<feature name="startApp">
|
||||
<param name="android-package" value="com.lampa.startapp.startApp" />
|
||||
</feature>
|
||||
```
|
||||
Add to ```/my-app/platforms/android/assets/www/cordova_plugins.js```:
|
||||
```javascript
|
||||
{
|
||||
"file": "plugins/com.lampa.startapp/www/startApp.js",
|
||||
"id": "com.lampa.startapp.startapp",
|
||||
"merges": [
|
||||
"navigator.startApp"
|
||||
]
|
||||
}
|
||||
```
|
||||
Add to ```/my-app/platforms/android/assets/www/plugins/com.lampa.startapp/www/``` file:
|
||||
https://github.com/lampaa/com.lampa.startapp/blob/master/www/startApp.js
|
||||
|
||||
Add to ```/my-app/platforms/android/src/com/lampa/startapp/``` file:
|
||||
https://github.com/lampaa/com.lampa.startapp/blob/master/src/android/startApp.java
|
||||
|
||||
NEW! [Script builder](/lampaa/com.lampa.startapp/MANUALLY_INSTALL.md)
|
||||
|
||||
|
||||
use: **ANDROID**
|
||||
|
||||
_Check application for installed_
|
||||
_Set appication parameters_
|
||||
|
||||
If success, returned application info: `versionName`, `packageName`, `versionCode` and `applicationInfo`.
|
||||
```javascript
|
||||
navigator.startApp.check("com.application.name", function(message) { /* success */
|
||||
console.log("app exists: ");
|
||||
console.log(message.versionName);
|
||||
console.log(message.packageName);
|
||||
console.log(message.versionCode);
|
||||
console.log(message.applicationInfo);
|
||||
},
|
||||
function(error) { /* error */
|
||||
console.log(error);
|
||||
var sApp = startApp.set({ /* params */
|
||||
"action":"ACTION_MAIN",
|
||||
"category":"CATEGORY_DEFAULT",
|
||||
"type":"text/css",
|
||||
"package":"com.lampa.startapp",
|
||||
"uri":"file://data/index.html",
|
||||
"intentstart":"startActivity",
|
||||
"flags":["FLAG_ACTIVITY_CLEAR_TOP","FLAG_ACTIVITY_CLEAR_TASK"],
|
||||
"component": ["com.app.name","com.app.name.Activity"]
|
||||
}, { /* extras */
|
||||
"extraKey1":"extraValue1",
|
||||
"extraKey2":"extraValue2"
|
||||
});
|
||||
```
|
||||
|
||||
_Start application without parameters_
|
||||
`action` these is a Intent action [Intent setAction](http://developer.android.com/reference/android/content/Intent.html#setAction(java.lang.String)) (optional, defaul null).
|
||||
|
||||
`category` these is a Intent method [Intent addCategory](http://developer.android.com/reference/android/content/Intent.html#addCategory(java.lang.String)) (optional, defaul null).
|
||||
|
||||
`type` these is a Intent method [Intent setType](http://developer.android.com/intl/ru/reference/android/content/Intent.html#setType(java.lang.String)) (optional, defaul null).
|
||||
|
||||
`package` (default null) these is a Intent method [Intent setPackage](http://developer.android.com/intl/ru/reference/android/content/Intent.html#setPackage(java.lang.String)) (optional, defaul null).
|
||||
|
||||
`uri` (default null) these is a Intent data Uri [Intent Uri](http://developer.android.com/intl/ru/reference/android/content/Intent.html#Intent(java.lang.String, android.net.Uri)) (optional, defaul null).
|
||||
|
||||
`flags` (default null) these is a Intent method [Intent setFlags](http://developer.android.com/reference/android/content/Intent.html#setFlags(int)) (optional, defaul null).
|
||||
|
||||
`component` (default null) these is a Intent method [Intent setComponent](http://developer.android.com/reference/android/content/Intent.html#setComponent(android.content.ComponentName)) (optional, defaul null).
|
||||
|
||||
|
||||
return ```startApp``` object:
|
||||
```javascript
|
||||
sApp.start(function() { /* success */
|
||||
console.log("OK");
|
||||
}, function(error) { /* fail */
|
||||
alert(error);
|
||||
});
|
||||
```
|
||||
or
|
||||
```javascript
|
||||
sApp.check(function(values) { /* success */
|
||||
console.log(values);
|
||||
}, function(error) { /* fail */
|
||||
alert(error);
|
||||
});
|
||||
```
|
||||
If success, values contains data: `versionName`, `packageName`, `versionCode` and `applicationInfo`.
|
||||
|
||||
|
||||
**Samples**
|
||||
|
||||
_Set application as only package name_:
|
||||
```js
|
||||
navigator.startApp.start("com.application.name", function(message) { /* success */
|
||||
console.log(message); // => OK
|
||||
},
|
||||
function(error) { /* error */
|
||||
console.log(error);
|
||||
var sApp = startApp.set({
|
||||
"package":"com.application.name"
|
||||
});
|
||||
```
|
||||
|
||||
_Start application with params. First variant with package and activity:
|
||||
_Set application as package and activity_:
|
||||
```js
|
||||
navigator.startApp.start([["com.app.name", "com.app.name.Activity"]], function(message) { /* success */
|
||||
console.log(message); // => OK
|
||||
},
|
||||
function(error) { /* error */
|
||||
console.log(error);
|
||||
var sApp = startApp.set({
|
||||
"component": ["com.app.name","com.app.name.Activity"]
|
||||
});
|
||||
```
|
||||
_Start application with params. Second variant with action and action params:
|
||||
|
||||
_Set application as action, package, type and Uri_:
|
||||
```js
|
||||
navigator.startApp.start([["action", "ACTION_NAME", "PACKAGE", "TYPE", "URI"]], function(message) { /* success */
|
||||
console.log(message); // => OK
|
||||
},
|
||||
function(error) { /* error */
|
||||
console.log(error);
|
||||
var sApp = startApp.set({ /* params */
|
||||
"action":"ACTION_MAIN",
|
||||
"type":"text/css",
|
||||
"package":"com.lampa.startapp",
|
||||
"uri":"file://data/index.html"
|
||||
});
|
||||
```
|
||||
`ACTION_NAME` these is a Intent flag [Intent Flags](http://developer.android.com/reference/android/content/Intent.html) (MAIN, VIEW, CALL, etc..).
|
||||
|
||||
`PACKAGE` these is a Intent method [setPackage](http://developer.android.com/intl/ru/reference/android/content/Intent.html#setPackage(java.lang.String)) (optional or set null)
|
||||
|
||||
`TYPE` these is a Intent method [setType](http://developer.android.com/intl/ru/reference/android/content/Intent.html#setType(java.lang.String)) (optional or set null)
|
||||
|
||||
`URI` these is a Intent data Uri [Uri](http://developer.android.com/intl/ru/reference/android/content/Intent.html#Intent(java.lang.String, android.net.Uri)) (optional or set null)
|
||||
|
||||
|
||||
> **Important!** First value of first parameter of _start_ method can be either a string or an array. And the array must contain two parameters. Example:
|
||||
>
|
||||
> ["com.app.name", [....]] or [["com.app.name", "com.app.name.Activity"] [....]]
|
||||
|
||||
|
||||
_Start application with only values_
|
||||
_Start application with extra fields_
|
||||
|
||||
```js
|
||||
navigator.startApp.start([[...], ["set_param1", "set_param2",..., "set_paramN"]], function(message) { /* success */
|
||||
console.log(message); // => OK
|
||||
},
|
||||
function(error) { /* error */
|
||||
console.log(error);
|
||||
var sApp = startApp.set({ /* params */
|
||||
"component": ["com.app.name","com.app.name.Activity"]
|
||||
}, { /* extras */
|
||||
"extraKey1":"extraValue1",
|
||||
"extraKey2":"extraValue2"
|
||||
});
|
||||
```
|
||||
_ANDROID: Start application with key:value parameters_
|
||||
|
||||
```js
|
||||
navigator.startApp.start([[...], [{"key1":"value1"},{"key2":"value2"}, {...}, {"keyN":"valueN"}]], function(message) { /* success */
|
||||
console.log(message); // => OK
|
||||
},
|
||||
function(error) { /* error */
|
||||
console.log(error);
|
||||
});
|
||||
```
|
||||
Example, call application with activity and key:value param:
|
||||
|
||||
```js
|
||||
navigator.startApp.start([["app.com.name", "app.com.name.Activity"], [{"product_id":"100"}]], ...);
|
||||
```
|
||||
|
||||
|
||||
|
||||
Example, call skype:
|
||||
```js
|
||||
navigator.startApp.start([["action", "VIEW"], ["skype:+79109999999"]], ...);
|
||||
startApp.set({ /* params */
|
||||
"action": "ACTION_VIEW",
|
||||
"uri": "skype:+79109999999"
|
||||
}).start();
|
||||
```
|
||||
Example, call phone:
|
||||
```js
|
||||
navigator.startApp.start([["action", "CALL"], ["tel:+79109999999"]], ...);
|
||||
startApp.set({ /* params */
|
||||
"action": "ACTION_CALL",
|
||||
"uri": "tel:+79109999999"
|
||||
}).start();
|
||||
```
|
||||
Example, call browser:
|
||||
```js
|
||||
navigator.startApp.start([["action", "VIEW"], ["https://github.com/lampaa"]], ...);
|
||||
startApp.set({ /* params */
|
||||
"action": "ACTION_VIEW",
|
||||
"uri": "https://github.com/lampaa"
|
||||
}).start();
|
||||
```
|
||||
Example, call facebook:
|
||||
```js
|
||||
navigator.startApp.start([["action", "VIEW"], ["fb://facewebmodal/f?href=https://www.facebook.com/GitHub"]], ...);
|
||||
startApp.set({ /* params */
|
||||
"action": "ACTION_VIEW",
|
||||
"uri": "fb://facewebmodal/f?href=https://www.facebook.com/GitHub"
|
||||
}).start();
|
||||
```
|
||||
Example, call whatsapp:
|
||||
```js
|
||||
navigator.startApp.start([["action", "SEND", "com.whatsapp", "text/plain"], [{"android.intent.extra.TEXT":"Text..."}]], ...);
|
||||
startApp.set({ /* params */
|
||||
"action": "ACTION_SEND",
|
||||
"package": "com.whatsapp",
|
||||
"type": "text/plain"
|
||||
}, {
|
||||
"android.intent.extra.TEXT":"Text..."
|
||||
}).start();
|
||||
```
|
||||
Example, call whatsapp chat:
|
||||
```js
|
||||
navigator.startApp.start([["action", "SEND", "com.whatsapp", "text/plain", "+79123456789"], [{"android.intent.extra.TEXT":"Text..."}, {"chat": true}]], ...);
|
||||
startApp.set({ /* params */
|
||||
"action": "ACTION_SEND",
|
||||
"package": "com.whatsapp",
|
||||
"type": "text/plain",
|
||||
"uri": "+79123456789"
|
||||
}, {
|
||||
"android.intent.extra.TEXT":"Text...",
|
||||
"chat": true
|
||||
}).start();
|
||||
```
|
||||
Example, call sms:
|
||||
```js
|
||||
startApp.set({ /* params */
|
||||
"action": "ACTION_MAIN",
|
||||
"category": "CATEGORY_DEFAULT",
|
||||
"type": "vnd.android-dir/mms-sms"
|
||||
}).start();
|
||||
```
|
||||
Example, play mp4 video:
|
||||
```js
|
||||
startApp.set({ /* params */
|
||||
"action": "ACTION_VIEW",
|
||||
"uri": "http://domain.com/videofile.mp4",
|
||||
"type": "video/mp4"
|
||||
}).start();
|
||||
```
|
||||
Example, open contacts book:
|
||||
```js
|
||||
startApp.set({ /* params */
|
||||
"action": "ACTION_PICK",
|
||||
"uri": "ContactsContract.Contacts.CONTENT_URI",
|
||||
"type": "video/mp4",
|
||||
"intentstart":"startActivityForResult"
|
||||
}).start();
|
||||
```
|
||||
|
||||
|
||||
|
||||
Use **iOS**
|
||||
|
||||
_Check iOS application for installed_
|
||||
_Set iOS application_
|
||||
|
||||
```js
|
||||
navigator.startApp.check("twitter://", function(message) { /* success */
|
||||
console.log(message); // => OK
|
||||
},
|
||||
function(error) { /* error */
|
||||
console.log(error);
|
||||
var sApp = startApp.set("twitter://");
|
||||
```
|
||||
|
||||
return ```startApp``` object:
|
||||
```javascript
|
||||
sApp.start(function() { /* success */
|
||||
console.log("OK");
|
||||
}, function(error) { /* fail */
|
||||
alert(error);
|
||||
});
|
||||
```
|
||||
or
|
||||
```javascript
|
||||
sApp.check(function(values) { /* success */
|
||||
console.log(values);
|
||||
}, function(error) { /* fail */
|
||||
alert(error);
|
||||
});
|
||||
```
|
||||
|
||||
_Start iOS application_
|
||||
|
||||
```js
|
||||
navigator.startApp.start("twitter://", function(message) { /* success */
|
||||
console.log(message); // => OK
|
||||
},
|
||||
function(error) { /* error */
|
||||
console.log(error);
|
||||
});
|
||||
```
|
||||
===========================================
|
||||
Tags:
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "cordova-plugin-startapp",
|
||||
"version": "0.0.6",
|
||||
"description": "Phonegap 3 plugin for check or launch other application in android device.",
|
||||
"name": "com.lampa.startapp",
|
||||
"version": "0.1.0",
|
||||
"description": "Phonegap plugin for check or launch other application in android device.",
|
||||
"cordova": {
|
||||
"id": "com.lampa.startapp",
|
||||
"platforms": [
|
||||
|
||||
@@ -2,15 +2,15 @@
|
||||
|
||||
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
||||
id="com.lampa.startapp"
|
||||
version="0.0.6">
|
||||
version="0.1.0">
|
||||
|
||||
<name>startApp</name>
|
||||
<description>Phonegap 3 plugin for check or launch other application in android device.</description>
|
||||
<description>Phonegap plugin for check or launch other application in android device.</description>
|
||||
<license>MIT</license>
|
||||
<keywords>cordova,startapp,lampa</keywords>
|
||||
|
||||
<js-module src="www/startApp.js" name="startapp">
|
||||
<merges target="navigator.startApp" />
|
||||
<merges target="startApp" />
|
||||
</js-module>
|
||||
|
||||
<!-- android -->
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
com.lampa.startapp
|
||||
https://github.com/lampaa/com.lampa.startapp
|
||||
|
||||
Phonegap 3 plugin for check or launch other application in android device (iOS support).
|
||||
Phonegap plugin for check or launch other application in android device (iOS support).
|
||||
bug tracker: https://github.com/lampaa/com.lampa.startapp/issues
|
||||
*/
|
||||
package com.lampa.startapp;
|
||||
@@ -18,17 +18,17 @@ import android.content.Intent;
|
||||
import android.content.ComponentName;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import java.util.Iterator;
|
||||
import android.net.Uri;
|
||||
import java.lang.reflect.Field;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.util.Log;
|
||||
import android.os.Bundle;
|
||||
|
||||
/**
|
||||
* This class provides access to vibration on the device.
|
||||
*/
|
||||
public class startApp extends CordovaPlugin {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public static final String TAG = "startApp";
|
||||
public startApp() { }
|
||||
|
||||
/**
|
||||
@@ -44,7 +44,13 @@ public class startApp extends CordovaPlugin {
|
||||
this.start(args, callbackContext);
|
||||
}
|
||||
else if(action.equals("check")) {
|
||||
this.check(args.getString(0), callbackContext);
|
||||
this.check(args, callbackContext);
|
||||
}
|
||||
else if(action.equals("getExtras")) {
|
||||
this.getExtras(callbackContext);
|
||||
}
|
||||
else if(action.equals("getExtra")) {
|
||||
this.getExtra(args, callbackContext);
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -57,148 +63,276 @@ public class startApp extends CordovaPlugin {
|
||||
* startApp
|
||||
*/
|
||||
public void start(JSONArray args, CallbackContext callback) {
|
||||
|
||||
Intent LaunchIntent;
|
||||
JSONObject params;
|
||||
JSONArray flags;
|
||||
JSONArray component;
|
||||
|
||||
String com_name = null;
|
||||
JSONObject extra;
|
||||
JSONObject key_value;
|
||||
String key;
|
||||
String value;
|
||||
|
||||
String activity = null;
|
||||
String spackage = null;
|
||||
String intetype = null;
|
||||
String intenuri = null;
|
||||
int i;
|
||||
|
||||
try {
|
||||
if (args.get(0) instanceof JSONArray) {
|
||||
com_name = args.getJSONArray(0).getString(0);
|
||||
activity = args.getJSONArray(0).getString(1);
|
||||
|
||||
|
||||
if (args.get(0) instanceof JSONObject) {
|
||||
params = args.getJSONObject(0);
|
||||
|
||||
if(args.getJSONArray(0).length() > 2) {
|
||||
spackage = args.getJSONArray(0).getString(2);
|
||||
}
|
||||
|
||||
if(args.getJSONArray(0).length() > 3) {
|
||||
intetype = args.getJSONArray(0).getString(3);
|
||||
}
|
||||
|
||||
if(args.getJSONArray(0).length() > 4) {
|
||||
intenuri = args.getJSONArray(0).getString(4);
|
||||
}
|
||||
}
|
||||
else {
|
||||
com_name = args.getString(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* call activity
|
||||
*/
|
||||
if(activity != null) {
|
||||
if(com_name.equals("action")) {
|
||||
/**
|
||||
* . < 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(activity);
|
||||
}
|
||||
/**
|
||||
* set package
|
||||
* http://developer.android.com/reference/android/content/Intent.html#setPackage(java.lang.String)
|
||||
*/
|
||||
if(params.has("package")) {
|
||||
LaunchIntent = cordova.getActivity().getPackageManager().getLaunchIntentForPackage(params.getString("package"));
|
||||
}
|
||||
else {
|
||||
LaunchIntent = new Intent();
|
||||
LaunchIntent.setComponent(new ComponentName(com_name, activity));
|
||||
LaunchIntent = new Intent();
|
||||
}
|
||||
|
||||
/**
|
||||
* set action
|
||||
* http://developer.android.com/intl/ru/reference/android/content/Intent.html#setAction%28java.lang.String%29
|
||||
*/
|
||||
if(params.has("action")) {
|
||||
LaunchIntent.setAction(getIntentValueString(params.getString("action")));
|
||||
}
|
||||
|
||||
/**
|
||||
* set category
|
||||
* http://developer.android.com/intl/ru/reference/android/content/Intent.html#addCategory%28java.lang.String%29
|
||||
*/
|
||||
if(params.has("category")) {
|
||||
LaunchIntent.addCategory(getIntentValueString(params.getString("category")));
|
||||
}
|
||||
|
||||
/**
|
||||
* set type
|
||||
* http://developer.android.com/intl/ru/reference/android/content/Intent.html#setType%28java.lang.String%29
|
||||
*/
|
||||
if(params.has("type")) {
|
||||
LaunchIntent.setType(params.getString("type"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* set data (uri)
|
||||
* http://developer.android.com/intl/ru/reference/android/content/Intent.html#setData%28android.net.Uri%29
|
||||
*/
|
||||
if(params.has("uri")) {
|
||||
LaunchIntent.setData(Uri.parse(params.getString("uri")));
|
||||
}
|
||||
|
||||
/**
|
||||
* set flags
|
||||
* http://developer.android.com/intl/ru/reference/android/content/Intent.html#addFlags%28int%29
|
||||
*/
|
||||
if(params.has("flags")) {
|
||||
flags = params.getJSONArray("flags");
|
||||
|
||||
for(i=0; i < flags.length(); i++) {
|
||||
LaunchIntent.addFlags(getIntentValue(flags.getString(i)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* set component
|
||||
* http://developer.android.com/intl/ru/reference/android/content/Intent.html#setComponent%28android.content.ComponentName%29
|
||||
*/
|
||||
if(params.has("component")) {
|
||||
component = params.getJSONArray("component");
|
||||
|
||||
if(component.length() == 2) {
|
||||
LaunchIntent.setComponent(new ComponentName(component.getString(0), component.getString(1)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* set extra fields
|
||||
*/
|
||||
if(!args.isNull(1)) {
|
||||
extra = args.getJSONObject(1);
|
||||
Iterator<String> iter = extra.keys();
|
||||
|
||||
while (iter.hasNext()) {
|
||||
key = iter.next();
|
||||
|
||||
value = extra.getString(key);
|
||||
LaunchIntent.putExtra(parseExtraName(key), value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* launch intent
|
||||
*/
|
||||
if(params.has("intentstart") && "startActivityForResult".equals(params.getString("intentstart"))) {
|
||||
cordova.getActivity().startActivityForResult(LaunchIntent, 1);
|
||||
}
|
||||
if(params.has("intentstart") && "sendBroadcast".equals(params.getString("intentstart"))) {
|
||||
cordova.getActivity().sendBroadcast(LaunchIntent);
|
||||
}
|
||||
else {
|
||||
cordova.getActivity().startActivity(LaunchIntent);
|
||||
}
|
||||
|
||||
callback.success();
|
||||
}
|
||||
else {
|
||||
LaunchIntent = this.cordova.getActivity().getPackageManager().getLaunchIntentForPackage(com_name);
|
||||
callback.error("Incorrect params, array is not array object!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
if(args.length() > 1) {
|
||||
JSONArray params = args.getJSONArray(1);
|
||||
JSONObject key_value;
|
||||
String key;
|
||||
String value;
|
||||
|
||||
for(int i = 0; i < params.length(); i++) {
|
||||
if (params.get(i) instanceof JSONObject) {
|
||||
Iterator<String> iter = params.getJSONObject(i).keys();
|
||||
|
||||
while (iter.hasNext()) {
|
||||
key = iter.next();
|
||||
try {
|
||||
value = params.getJSONObject(i).getString(key);
|
||||
|
||||
LaunchIntent.putExtra(key, value);
|
||||
} catch (JSONException e) {
|
||||
callback.error("json params: " + e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
LaunchIntent.setData(Uri.parse(params.getString(i)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* start activity
|
||||
*/
|
||||
this.cordova.getActivity().startActivity(LaunchIntent);
|
||||
callback.success();
|
||||
|
||||
} catch (JSONException e) {
|
||||
callback.error("json: " + e.toString());
|
||||
} catch (Exception e) {
|
||||
callback.error("intent: " + e.toString());
|
||||
}
|
||||
}
|
||||
catch (JSONException e) {
|
||||
callback.error("JSONException: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch (IllegalAccessException e) {
|
||||
callback.error("IllegalAccessException: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch (NoSuchFieldException e) {
|
||||
callback.error("NoSuchFieldException: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch (ActivityNotFoundException e) {
|
||||
callback.error("ActivityNotFoundException: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* checkApp
|
||||
*/
|
||||
public void check(String component, CallbackContext callback) {
|
||||
PackageManager pm = this.cordova.getActivity().getApplicationContext().getPackageManager();
|
||||
public void check(JSONArray args, CallbackContext callback) {
|
||||
JSONObject params;
|
||||
|
||||
try {
|
||||
/**
|
||||
* get package info
|
||||
*/
|
||||
PackageInfo PackInfo = pm.getPackageInfo(component, PackageManager.GET_ACTIVITIES);
|
||||
|
||||
/**
|
||||
* create json object
|
||||
*/
|
||||
JSONObject info = new JSONObject();
|
||||
|
||||
info.put("versionName", PackInfo.versionName);
|
||||
info.put("packageName", PackInfo.packageName);
|
||||
info.put("versionCode", PackInfo.versionCode);
|
||||
info.put("applicationInfo", PackInfo.applicationInfo);
|
||||
|
||||
callback.success(info);
|
||||
} catch (Exception e) {
|
||||
callback.error(e.toString());
|
||||
if (args.get(0) instanceof JSONObject) {
|
||||
params = args.getJSONObject(0);
|
||||
|
||||
|
||||
if(params.has("package")) {
|
||||
PackageManager pm = cordova.getActivity().getApplicationContext().getPackageManager();
|
||||
|
||||
/**
|
||||
* get package info
|
||||
*/
|
||||
PackageInfo PackInfo = pm.getPackageInfo(params.getString("package"), PackageManager.GET_ACTIVITIES);
|
||||
|
||||
/**
|
||||
* create json object
|
||||
*/
|
||||
JSONObject info = new JSONObject();
|
||||
|
||||
info.put("versionName", PackInfo.versionName);
|
||||
info.put("packageName", PackInfo.packageName);
|
||||
info.put("versionCode", PackInfo.versionCode);
|
||||
info.put("applicationInfo", PackInfo.applicationInfo);
|
||||
|
||||
callback.success(info);
|
||||
}
|
||||
else {
|
||||
callback.error("Value \"package\" in null!");
|
||||
}
|
||||
}
|
||||
else {
|
||||
callback.error("Incorrect params, array is not array object!");
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
callback.error("json: " + e.toString());
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch (NameNotFoundException e) {
|
||||
callback.error("NameNotFoundException: " + e.toString());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* getExtras
|
||||
*/
|
||||
public void getExtras(CallbackContext callback) {
|
||||
try {
|
||||
Bundle extras = cordova.getActivity().getIntent().getExtras();
|
||||
JSONObject info = new JSONObject();
|
||||
|
||||
if (extras != null) {
|
||||
for (String key : extras.keySet()) {
|
||||
info.put(key, extras.get(key).toString());
|
||||
}
|
||||
}
|
||||
|
||||
callback.success(info);
|
||||
}
|
||||
catch(JSONException e) {
|
||||
callback.error(e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* getExtra
|
||||
*/
|
||||
public void getExtra(JSONArray args, CallbackContext callback) {
|
||||
try {
|
||||
String extraName = parseExtraName(args.getString(0));
|
||||
Intent extraIntent = cordova.getActivity().getIntent();
|
||||
|
||||
if(extraIntent.hasExtra(extraName)) {
|
||||
String extraValue = extraIntent.getStringExtra(extraName);
|
||||
|
||||
if (extraValue == null) {
|
||||
extraValue = ((Uri) extraIntent.getParcelableExtra(extraName)).toString();
|
||||
}
|
||||
|
||||
callback.success(extraValue);
|
||||
}
|
||||
else {
|
||||
callback.error("extra field not found");
|
||||
}
|
||||
}
|
||||
catch(JSONException e) {
|
||||
callback.error(e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* static functions
|
||||
*/
|
||||
static String parseExtraName(String extraName) {
|
||||
String parseIntentExtra = extraName;
|
||||
|
||||
try {
|
||||
parseIntentExtra = getIntentValueString(extraName);
|
||||
Log.i(TAG, parseIntentExtra);
|
||||
}
|
||||
catch(NoSuchFieldException e) {
|
||||
parseIntentExtra = extraName;
|
||||
}
|
||||
catch(IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
return extraName;
|
||||
}
|
||||
|
||||
Log.e(TAG, parseIntentExtra);
|
||||
|
||||
return parseIntentExtra;
|
||||
}
|
||||
|
||||
static String getIntentValueString(String flag) throws NoSuchFieldException, IllegalAccessException {
|
||||
Field field = Intent.class.getDeclaredField(flag);
|
||||
field.setAccessible(true);
|
||||
|
||||
return (String) field.get(null);
|
||||
}
|
||||
|
||||
static int getIntentValue(String flag) throws NoSuchFieldException, IllegalAccessException {
|
||||
Field field = Intent.class.getDeclaredField(flag);
|
||||
field.setAccessible(true);
|
||||
|
||||
return field.getInt(null);
|
||||
}
|
||||
}
|
||||
|
||||
387
test/index.html
Normal file
387
test/index.html
Normal file
@@ -0,0 +1,387 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1, maximum-scale=1, user-scalable=no">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta charset="utf-8" />
|
||||
<title>com.lampa.startapp test file</title>
|
||||
|
||||
<style>
|
||||
html, body {
|
||||
margin:0;
|
||||
padding:0;
|
||||
font: 14px arial;
|
||||
}
|
||||
#left {
|
||||
float: left;
|
||||
width: 50%;
|
||||
height: 100%;
|
||||
}
|
||||
#right {
|
||||
border-left: 3px #ccc solid;
|
||||
width: 50%;
|
||||
max-width: 50%;
|
||||
margin-left:-3px;
|
||||
float: right;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
label {
|
||||
display: block;
|
||||
padding: 20px;
|
||||
border-bottom: 3px blue solid;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
label input, label select {
|
||||
border: 2px gray solid;
|
||||
box-sizing:content-box;
|
||||
display: block;
|
||||
margin-top: 5px;
|
||||
text-transform: none;
|
||||
width: 90%;
|
||||
padding: 2px;
|
||||
}
|
||||
|
||||
label input:focus, label select:focus {
|
||||
border: 2px blue solid;
|
||||
}
|
||||
|
||||
.extras input {
|
||||
width: 35%;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.l_stype {
|
||||
text-transform: none;
|
||||
}
|
||||
.l_stype input {
|
||||
width: auto;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
#result {
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
#template {
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
<script type='text/javascript' src='cordova.js'></script>
|
||||
<script type='text/javascript' src='jquery.js'></script>
|
||||
<script type='text/javascript' src='test.js'></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id='left'>
|
||||
<form>
|
||||
<label>
|
||||
Intent action
|
||||
<select id='action' name='action[0]'>
|
||||
<option></option>
|
||||
<option>ACTION_MAIN</option>
|
||||
<option>ACTION_VIEW</option>
|
||||
<option>ACTION_DIAL</option>
|
||||
<option>ACTION_CALL</option>
|
||||
<option>ACTION_SEND</option>
|
||||
<option>ACTION_PICK</option>
|
||||
<option>ACTION_EDIT</option>
|
||||
<option>ACTION_ANSWER</option>
|
||||
<option>ACTION_DELETE</option>
|
||||
<option>ACTION_RUN</option>
|
||||
<option>ACTION_SYNC</option>
|
||||
<option>ACTION_SENDTO</option>
|
||||
<option>ACTION_CHOOSER</option>
|
||||
<option>ACTION_SEARCH</option>
|
||||
<option>ACTION_WEB_SEARCH</option>
|
||||
|
||||
<option>ACTION_ALL_APPS</option>
|
||||
<option>ACTION_APP_ERROR</option>
|
||||
<option>ACTION_ASSIST</option>
|
||||
<option>ACTION_BUG_REPORT</option>
|
||||
<option>ACTION_CALL_BUTTON</option>
|
||||
<option>ACTION_CREATE_DOCUMENT</option>
|
||||
<option>ACTION_CREATE_SHORTCUT</option>
|
||||
<option>ACTION_FACTORY_TEST</option>
|
||||
<option>ACTION_GET_CONTENT</option>
|
||||
<option>ACTION_INSERT</option>
|
||||
<option>ACTION_PASTE</option>
|
||||
<option>ACTION_INSERT_OR_EDIT</option>
|
||||
<option>ACTION_INSTALL_PACKAGE</option>
|
||||
<option>ACTION_MANAGE_NETWORK_USAGE</option>
|
||||
<option>ACTION_OPEN_DOCUMENT</option>
|
||||
<option>ACTION_OPEN_DOCUMENT_TREE</option>
|
||||
<option>ACTION_PICK_ACTIVITY</option>
|
||||
<option>ACTION_POWER_USAGE_SUMMARY</option>
|
||||
<option>ACTION_PROCESS_TEXT</option>
|
||||
<option>ACTION_SEARCH_LONG_PRESS</option>
|
||||
<option>ACTION_SEND_MULTIPLE</option>
|
||||
<option>ACTION_SET_WALLPAPER</option>
|
||||
<option>ACTION_SYSTEM_TUTORIAL</option>
|
||||
<option>ACTION_UNINSTALL_PACKAGE</option>
|
||||
<option>ACTION_VOICE_COMMAND</option>
|
||||
</select>
|
||||
|
||||
OR <input type='text' name='action[1]' placeholder='ACTION_MAIN'>
|
||||
</label>
|
||||
|
||||
<label>
|
||||
Category
|
||||
<select id='category' name='category[0]'>
|
||||
<option></option>
|
||||
<option>CATEGORY_ALTERNATIVE</option>
|
||||
<option>CATEGORY_APP_BROWSER</option>
|
||||
<option>CATEGORY_APP_CALCULATOR</option>
|
||||
<option>CATEGORY_APP_CALENDAR</option>
|
||||
<option>CATEGORY_APP_CONTACTS</option>
|
||||
<option>CATEGORY_APP_EMAIL</option>
|
||||
<option>CATEGORY_APP_GALLERY</option>
|
||||
<option>CATEGORY_APP_MAPS</option>
|
||||
<option>CATEGORY_APP_MARKET</option>
|
||||
<option>CATEGORY_APP_MESSAGING</option>
|
||||
<option>CATEGORY_APP_MUSIC</option>
|
||||
<option>CATEGORY_BROWSABLE</option>
|
||||
<option>CATEGORY_CAR_DOCK</option>
|
||||
<option>CATEGORY_CAR_MODE</option>
|
||||
<option>CATEGORY_DEFAULT</option>
|
||||
<option>CATEGORY_DESK_DOCK</option>
|
||||
<option>CATEGORY_DEVELOPMENT_PREFERENCE</option>
|
||||
<option>CATEGORY_EMBED</option>
|
||||
<option>CATEGORY_FRAMEWORK_INSTRUMENTATION_TEST</option>
|
||||
<option>CATEGORY_HE_DESK_DOCK</option>
|
||||
<option>CATEGORY_HOME</option>
|
||||
<option>CATEGORY_INFO</option>
|
||||
<option>CATEGORY_LAUNCHER</option>
|
||||
<option>CATEGORY_LEANBACK_LAUNCHER</option>
|
||||
<option>CATEGORY_LE_DESK_DOCK</option>
|
||||
<option>CATEGORY_MONKEY</option>
|
||||
<option>CATEGORY_OPENABLE</option>
|
||||
<option>CATEGORY_PREFERENCE</option>
|
||||
<option>CATEGORY_SAMPLE_CODE</option>
|
||||
<option>CATEGORY_SELECTED_ALTERNATIVE</option>
|
||||
<option>CATEGORY_TAB</option>
|
||||
<option>CATEGORY_TEST</option>
|
||||
<option>CATEGORY_UNIT_TEST</option>
|
||||
<option>CATEGORY_VOICE</option>
|
||||
</select>
|
||||
|
||||
OR <input type='text' name='categpry[1]' placeholder='CATEGORY_HOME'>
|
||||
</label>
|
||||
|
||||
<label>
|
||||
Type (explicit MIME data type)
|
||||
<select id='type' name='type[0]'>
|
||||
<option></option>
|
||||
|
||||
<optgroup label="text">
|
||||
<option>text/css</option>
|
||||
<option>text/csv</option>
|
||||
<option>text/html</option>
|
||||
<option>text/javascript</option>
|
||||
<option>text/plain</option>
|
||||
<option>text/xml</option>
|
||||
</optgroup>
|
||||
|
||||
<optgroup label="video">
|
||||
<option>video/mpeg</option>
|
||||
<option>video/mp4</option>
|
||||
<option>video/ogg</option>
|
||||
<option>video/quicktime</option>
|
||||
<option>video/webm</option>
|
||||
<option>video/x-ms-wmv</option>
|
||||
<option>video/x-flv</option>
|
||||
<option>video/3gpp</option>
|
||||
<option>video/3gpp2</option>
|
||||
</optgroup>
|
||||
|
||||
<optgroup label="image">
|
||||
<option>image/gif</option>
|
||||
<option>image/jpeg</option>
|
||||
<option>image/png</option>
|
||||
<option>image/pjpeg</option>
|
||||
<option>image/svg+xml</option>
|
||||
<option>image/tiff</option>
|
||||
<option>image/vnd.microsoft.icon</option>
|
||||
<option>image/vnd.wap.wbmp</option>
|
||||
<option></option>
|
||||
</optgroup>
|
||||
|
||||
<optgroup label="audio">
|
||||
<option>audio/basic</option>
|
||||
<option>audio/L24</option>
|
||||
<option>audio/mp4</option>
|
||||
<option>audio/aac</option>
|
||||
<option>audio/mpeg</option>
|
||||
<option>audio/ogg</option>
|
||||
<option>audio/vorbis</option>
|
||||
<option>audio/x-ms-wma</option>
|
||||
<option>audio/x-ms-wax</option>
|
||||
<option>audio/vnd.rn-realaudio</option>
|
||||
<option>audio/vnd.wave</option>
|
||||
<option>audio/webm</option>
|
||||
</optgroup>
|
||||
|
||||
<optgroup label="vnd">
|
||||
<option>vnd.android-dir/mms-sms</option>
|
||||
</optgroup>
|
||||
|
||||
<optgroup label="application">
|
||||
<option>application/atom+xml</option>
|
||||
<option>application/EDI-X12</option>
|
||||
<option>application/EDIFACT</option>
|
||||
<option>application/json</option>
|
||||
<option>application/javascript</option>
|
||||
<option>application/octet-stream</option>
|
||||
<option>application/ogg</option>
|
||||
<option>application/pdf</option>
|
||||
<option>application/postscript</option>
|
||||
<option>application/soap+xml</option>
|
||||
<option>application/font-woff</option>
|
||||
<option>application/xhtml+xml</option>
|
||||
<option>application/xml-dtd</option>
|
||||
<option>application/xop+xml</option>
|
||||
<option>application/zip</option>
|
||||
<option>application/gzip</option>
|
||||
<option>application/x-bittorrent</option>
|
||||
<option>application/x-tex</option>
|
||||
</optgroup>
|
||||
|
||||
<optgroup label="multipart">
|
||||
<option>multipart/mixed</option>
|
||||
<option>multipart/alternative</option>
|
||||
<option>multipart/related</option>
|
||||
<option>multipart/form-data</option>
|
||||
<option>multipart/signed</option>
|
||||
<option>multipart/encrypted</option>
|
||||
</optgroup>
|
||||
|
||||
<optgroup label="application/x">
|
||||
<option>application/x-www-form-urlencoded</option>
|
||||
<option>application/x-dvi</option>
|
||||
<option>application/x-latex</option>
|
||||
<option>application/x-font-ttf</option>
|
||||
<option>application/x-shockwave-flash</option>
|
||||
<option>application/x-stuffit</option>
|
||||
<option>application/x-rar-compressed</option>
|
||||
<option>application/x-tar</option>
|
||||
<option>text/x-jquery-tmpl</option>
|
||||
<option>application/x-javascript</option>
|
||||
</optgroup>
|
||||
</select>
|
||||
|
||||
OR <input name='type[1]' placeholder='text/plain'>
|
||||
</label>
|
||||
|
||||
<label>
|
||||
Package
|
||||
<input name='package[0]' placeholder='com.application.name'>
|
||||
</label>
|
||||
|
||||
<label>
|
||||
Component
|
||||
<div class='extras'>
|
||||
<input type='text' name='component[0]' placeholder="com.application.name">
|
||||
<input type='text' name='component[1]' placeholder="com.application.name.MyActivity">
|
||||
</div>
|
||||
</label>
|
||||
|
||||
<label>
|
||||
Uri
|
||||
<input name='uri[0]' placeholder='file:///sdcard/index.html'>
|
||||
</label>
|
||||
|
||||
<label>
|
||||
Flags
|
||||
<select multiple name='flags[0]'>
|
||||
<option></option>
|
||||
<option>FLAG_ACTIVITY_CLEAR_TOP</option>
|
||||
<option>FLAG_ACTIVITY_CLEAR_TASK</option>
|
||||
<option>FLAG_ACTIVITY_SINGLE_TOP</option>
|
||||
<option>FLAG_ACTIVITY_BROUGHT_TO_FRONT</option>
|
||||
<option>FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET</option>
|
||||
<option>FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS</option>
|
||||
<option>FLAG_ACTIVITY_FORWARD_RESULT</option>
|
||||
<option>FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY</option>
|
||||
<option>FLAG_ACTIVITY_MULTIPLE_TASK</option>
|
||||
<option>FLAG_ACTIVITY_NEW_DOCUMENT</option>
|
||||
<option>FLAG_ACTIVITY_NEW_TASK</option>
|
||||
<option>FLAG_ACTIVITY_NO_ANIMATION</option>
|
||||
<option>FLAG_ACTIVITY_NO_HISTORY</option>
|
||||
<option>FLAG_ACTIVITY_NO_USER_ACTION</option>
|
||||
<option>FLAG_ACTIVITY_PREVIOUS_IS_TOP</option>
|
||||
<option>FLAG_ACTIVITY_REORDER_TO_FRONT</option>
|
||||
<option>FLAG_ACTIVITY_RESET_TASK_IF_NEEDED</option>
|
||||
<option>FLAG_ACTIVITY_RETAIN_IN_RECENTS</option>
|
||||
<option>FLAG_ACTIVITY_TASK_ON_HOME</option>
|
||||
<option>FLAG_DEBUG_LOG_RESOLUTION</option>
|
||||
<option>FLAG_EXCLUDE_STOPPED_PACKAGES</option>
|
||||
<option>FLAG_FROM_BACKGROUND</option>
|
||||
<option>FLAG_GRANT_PERSISTABLE_URI_PERMISSION</option>
|
||||
<option>FLAG_GRANT_PREFIX_URI_PERMISSION</option>
|
||||
<option>FLAG_GRANT_READ_URI_PERMISSION</option>
|
||||
<option>FLAG_GRANT_WRITE_URI_PERMISSION</option>
|
||||
<option>FLAG_INCLUDE_STOPPED_PACKAGES</option>
|
||||
<option>FLAG_RECEIVER_FOREGROUND</option>
|
||||
<option>FLAG_RECEIVER_NO_ABORT</option>
|
||||
<option>FLAG_RECEIVER_REGISTERED_ONLY</option>
|
||||
<option>FLAG_RECEIVER_REPLACE_PENDING</option>
|
||||
</select>
|
||||
</label>
|
||||
|
||||
|
||||
<label class='l_extras'>
|
||||
Extras
|
||||
<div class='extras'>
|
||||
<input type='text' name='extras[0][0]'> =
|
||||
<input type='text' name='extras[0][1]'>
|
||||
<button class='remove_extras' type='button'>- Remove</button>
|
||||
</div> <button id='add_extras' type='button'>+ Add</button>
|
||||
</label>
|
||||
|
||||
<label class='l_stype'>
|
||||
START TYPE:
|
||||
|
||||
<input type='radio' name='intentstart' value='startActivity' checked> startActivity()
|
||||
|
||||
<input type='radio' name='intentstart' value='startActivityForResult'> startActivityForResult()
|
||||
|
||||
<input type='radio' name='intentstart' value='sendBroadcast'> sendBroadcast()
|
||||
</label>
|
||||
|
||||
<button id='build' type='button'>build</button>
|
||||
<button id='run' type='button'>run</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div id='right'>
|
||||
Script builder
|
||||
|
||||
<pre id='result'>
|
||||
|
||||
</pre>
|
||||
|
||||
<div id='template'>
|
||||
var sApp = startApp.set({ /* params */
|
||||
{$VALUES$}
|
||||
}, {$EXTRAS$});
|
||||
|
||||
|
||||
sApp.check(function(values) { /* success */
|
||||
console.log(values)
|
||||
}, function(error) { /* fail */
|
||||
alert(error);
|
||||
});
|
||||
|
||||
sApp.start(function() { /* success */
|
||||
console.log(values)
|
||||
}, function(error) { /* fail */
|
||||
alert(error);
|
||||
});
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
5
test/jquery.js
vendored
Normal file
5
test/jquery.js
vendored
Normal file
File diff suppressed because one or more lines are too long
134
test/test.js
Normal file
134
test/test.js
Normal file
@@ -0,0 +1,134 @@
|
||||
var TAG = "TEST";
|
||||
var LAST_EXTRA = 0;
|
||||
var ONE_TO_PARAM = ['action', 'uri', 'package', 'type', 'category', 'intentstart'];
|
||||
|
||||
jQuery(document).on('deviceready ready', function(e) {
|
||||
console.log(TAG, e.type);
|
||||
|
||||
var TEMPLATE = $('#template').html();
|
||||
var $result = $('#result');
|
||||
|
||||
/**
|
||||
* form builder
|
||||
*/
|
||||
$('form input, form select, form').on('change build', function() {
|
||||
var data = $('form').serializeArray();
|
||||
var build = {};
|
||||
var array_build = [];
|
||||
var i, g;
|
||||
var flags = [];
|
||||
var extras = [];
|
||||
var extras_assoc = {};
|
||||
var extras_build = [];
|
||||
var component = [];
|
||||
var match;
|
||||
var key;
|
||||
var out = "";
|
||||
|
||||
for(var i=0; i < data.length; i++) {
|
||||
console.log(data[i].name, data[i].name.indexOf('action'));
|
||||
|
||||
for(g=0; g < ONE_TO_PARAM.length; g++) {
|
||||
if(data[i].name.indexOf(ONE_TO_PARAM[g]) != -1) {
|
||||
if(data[i].value) {
|
||||
build[ONE_TO_PARAM[g]] = '"'+ONE_TO_PARAM[g]+'":"'+data[i].value+'"';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(data[i].name.indexOf('flags') != -1) {
|
||||
if(data[i].value) {
|
||||
flags.push(data[i].value);
|
||||
}
|
||||
}
|
||||
|
||||
if(data[i].name.indexOf('component') != -1) {
|
||||
if(data[i].value) {
|
||||
component.push(data[i].value);
|
||||
}
|
||||
}
|
||||
|
||||
if(data[i].name.indexOf('extras') != -1) {
|
||||
if(data[i].value) {
|
||||
match = data[i].name.match(/\[([0-9]+)\]/);
|
||||
|
||||
if(extras[match[1]] == undefined) {
|
||||
extras[match[1]] = [];
|
||||
}
|
||||
|
||||
extras[match[1]].push(data[i].value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// flags
|
||||
if(flags.length > 0) {
|
||||
build['flags'] = '"flags":["'+flags.join('","')+'"]';
|
||||
}
|
||||
|
||||
// component
|
||||
if(component.length > 0) {
|
||||
build['component'] = '"component": ["'+component.join('","')+'"]';
|
||||
}
|
||||
|
||||
// component
|
||||
if(extras.length > 0) {
|
||||
for(i=0; i < extras.length; i++) {
|
||||
if(extras[i][0] && extras[i][1]) {
|
||||
extras_assoc[extras[i][0]] = extras[i][1];
|
||||
}
|
||||
}
|
||||
|
||||
for (key in extras_assoc) {
|
||||
extras_build.push('"'+key+'":"'+extras_assoc[key]+'"');
|
||||
}
|
||||
}
|
||||
|
||||
console.log(extras_build);
|
||||
|
||||
|
||||
|
||||
for (key in build) {
|
||||
array_build.push(build[key]);
|
||||
}
|
||||
|
||||
out = TEMPLATE
|
||||
.replace('{$VALUES$}', array_build.join(",\n "))
|
||||
.replace('{$EXTRAS$}', "{ /* extras */\n " + extras_build.join(",\n ") + "\n}");
|
||||
|
||||
|
||||
$result.html(out);
|
||||
});
|
||||
|
||||
/**
|
||||
* buttons
|
||||
*/
|
||||
$('#build').on('click', function() {
|
||||
$('form').trigger('build');
|
||||
});
|
||||
|
||||
$('#run').on('click', function() {
|
||||
// eval
|
||||
console.log(new Function($result.html()));
|
||||
});
|
||||
|
||||
/**
|
||||
* extras
|
||||
*/
|
||||
$('#add_extras').on('click', function() {
|
||||
LAST_EXTRA++;
|
||||
|
||||
$(this).before("<div class='extras'>\
|
||||
<input type='text' name='extras["+LAST_EXTRA+"][0]'> = \
|
||||
<input type='text' name='extras["+LAST_EXTRA+"][1]'>\
|
||||
<button class='remove_extras' type='button'>- Remove</button>\
|
||||
</div>");
|
||||
});
|
||||
|
||||
$('.l_extras').on('click', '.remove_extras', function() {
|
||||
if(confirm('Really delete?')) {
|
||||
$(this).parent().remove();
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -1,34 +1,60 @@
|
||||
cordova.define("com.lampa.startapp", function(require, exports, module) {
|
||||
/**
|
||||
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
|
||||
|
||||
!! THIS SCRIPT FILE TO CORDOVA 3.5.*
|
||||
If you are using a version lower than 3.5, read this theme: https://github.com/lampaa/org.apache.cordova.startapp/issues/5#issuecomment-49974214
|
||||
Phonegap plugin for check or launch other application in android device (iOS support).
|
||||
bug tracker: https://github.com/lampaa/com.lampa.startapp/issues
|
||||
*/
|
||||
|
||||
var exec = require('cordova/exec');
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* Check application for installed on device
|
||||
* Set application params
|
||||
*
|
||||
* @param {String} message app name
|
||||
* @param {Function} completeCallback The callback that is called when open app
|
||||
* @param {Function} errorCallback The callback that is called when application is not installed
|
||||
*/
|
||||
check: function(message, completeCallback, errorCallback) {
|
||||
exec(completeCallback, errorCallback, "startApp", "check", [message]);
|
||||
},
|
||||
/**
|
||||
* Start application on device
|
||||
*
|
||||
* @param {Mixed} message params, view documentation https://github.com/lampaa/com.lampa.startapp
|
||||
* @param {Function} completeCallback The callback that is called when open app
|
||||
* @param {Mixed} params params, view documentation https://github.com/lampaa/com.lampa.startapp
|
||||
* @param {Mixed} extra Extra fields
|
||||
* @param {Function} errorCallback The callback that is called when an error occurred when the program starts.
|
||||
*
|
||||
*/
|
||||
start: function(message, completeCallback, errorCallback) {
|
||||
exec(completeCallback, errorCallback, "startApp", "start", (typeof message === 'string') ? [message] : message);
|
||||
}
|
||||
|
||||
set: function(params, extra) {
|
||||
var output = [params];
|
||||
|
||||
if(extra != undefined) {
|
||||
output.push(extra);
|
||||
}
|
||||
else {
|
||||
output.push(null);
|
||||
}
|
||||
|
||||
return {
|
||||
start: function(completeCallback, errorCallback) {
|
||||
completeCallback = completeCallback || function() {};
|
||||
errorCallback = errorCallback || function() {};
|
||||
|
||||
exec(completeCallback, errorCallback, "startApp", "start", output);
|
||||
},
|
||||
check: function(completeCallback, errorCallback) {
|
||||
completeCallback = completeCallback || function() {};
|
||||
errorCallback = errorCallback || function() {};
|
||||
|
||||
exec(completeCallback, errorCallback, "startApp", "check", output);
|
||||
}
|
||||
}
|
||||
},
|
||||
/**
|
||||
* extra values
|
||||
*/
|
||||
getExtras: function(completeCallback, errorCallback) {
|
||||
exec(completeCallback, errorCallback, "startApp", "getExtras", []);
|
||||
},
|
||||
getExtra: function(extraValue, completeCallback, errorCallback) {
|
||||
exec(completeCallback, errorCallback, "startApp", "getExtra", [extraValue]);
|
||||
},
|
||||
hasExtra: function(extraValue, completeCallback, errorCallback) {
|
||||
this.getExtra(extraValue, completeCallback, errorCallback);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
cordova.define("com.lampa.startapp.startApp", function(require, exports, module) {
|
||||
/**
|
||||
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
|
||||
|
||||
!! THIS SCRIPT FILE TO CORDOVA 3.0.*
|
||||
If you are using a version upper than 3.5, read this theme: https://github.com/lampaa/org.apache.cordova.startapp/issues/5#issuecomment-49974214
|
||||
*/
|
||||
|
||||
var exec = require('cordova/exec');
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* Check application for installed on device
|
||||
*
|
||||
* @param {String} message app name
|
||||
* @param {Function} completeCallback The callback that is called when open app
|
||||
* @param {Function} errorCallback The callback that is called when application is not installed
|
||||
*/
|
||||
check: function(message, completeCallback, errorCallback) {
|
||||
exec(completeCallback, errorCallback, "startApp", "check", [message]);
|
||||
},
|
||||
/**
|
||||
* Start application on device
|
||||
*
|
||||
* @param {Mixed} message params, view documentation https://github.com/lampaa/com.lampa.startapp
|
||||
* @param {Function} completeCallback The callback that is called when open app
|
||||
* @param {Function} errorCallback The callback that is called when an error occurred when the program starts.
|
||||
*/
|
||||
start: function(message, completeCallback, errorCallback) {
|
||||
exec(completeCallback, errorCallback, "startApp", "start", (typeof message === 'string') ? [message] : message);
|
||||
}
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user