mirror of
https://github.com/lampaa/com.lampa.startapp.git
synced 2026-05-01 00:00:05 +08:00
updates 6.1.0
Add full support activityForResult, sendBroadcast and RegisterReceiver. Add types of extras.
This commit is contained in:
+1
-6
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
||||||
id="com.lampa.startapp"
|
id="com.lampa.startapp"
|
||||||
version="0.1.4">
|
version="6.1.0">
|
||||||
|
|
||||||
<name>startApp</name>
|
<name>startApp</name>
|
||||||
<description>Phonegap plugin for check or launch other application in android device.</description>
|
<description>Phonegap plugin for check or launch other application in android device.</description>
|
||||||
@@ -20,11 +20,6 @@
|
|||||||
<param name="android-package" value="com.lampa.startapp.startApp"/>
|
<param name="android-package" value="com.lampa.startapp.startApp"/>
|
||||||
</feature>
|
</feature>
|
||||||
</config-file>
|
</config-file>
|
||||||
<config-file target="AndroidManifest.xml" parent="/*/application">
|
|
||||||
<provider android:authorities="com.lampa.startapp.fileProvider" android:exported="false" android:grantUriPermissions="true" android:name="android.support.v4.content.FileProvider">
|
|
||||||
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" />
|
|
||||||
</provider>
|
|
||||||
</config-file>
|
|
||||||
|
|
||||||
<source-file src="src/android/startApp.java" target-dir="src/com/lampa/startapp" />
|
<source-file src="src/android/startApp.java" target-dir="src/com/lampa/startapp" />
|
||||||
<source-file src="src/android/res/xml/file_paths.xml" target-dir="res/xml" />
|
<source-file src="src/android/res/xml/file_paths.xml" target-dir="res/xml" />
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
package com.lampa.startapp;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import org.apache.cordova.CordovaPlugin;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by User on 16.05.2018.
|
||||||
|
*/
|
||||||
|
public class Assets extends CordovaPlugin {
|
||||||
|
protected static final String TAG = "startApp";
|
||||||
|
protected boolean NO_PARSE_INTENT_VALS = false;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* functions
|
||||||
|
*/
|
||||||
|
protected String parseExtraName(String extraName) {
|
||||||
|
String parseIntentExtra = extraName;
|
||||||
|
|
||||||
|
try {
|
||||||
|
parseIntentExtra = getIntentValueString(extraName);
|
||||||
|
}
|
||||||
|
catch(NoSuchFieldException e) {
|
||||||
|
parseIntentExtra = extraName;
|
||||||
|
}
|
||||||
|
catch(IllegalAccessException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return extraName;
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.e(TAG, parseIntentExtra);
|
||||||
|
|
||||||
|
return parseIntentExtra;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected int getIntentValue(String flag) throws NoSuchFieldException, IllegalAccessException {
|
||||||
|
Field field = Intent.class.getDeclaredField(flag);
|
||||||
|
field.setAccessible(true);
|
||||||
|
|
||||||
|
return field.getInt(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
+148
-131
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
com.lampa.startapp
|
com.lampa.startapp, ver. 6.1.0
|
||||||
https://github.com/lampaa/com.lampa.startapp
|
https://github.com/lampaa/com.lampa.startapp
|
||||||
|
|
||||||
Phonegap 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).
|
||||||
@@ -8,35 +8,27 @@
|
|||||||
package com.lampa.startapp;
|
package com.lampa.startapp;
|
||||||
|
|
||||||
import org.apache.cordova.CallbackContext;
|
import org.apache.cordova.CallbackContext;
|
||||||
import org.apache.cordova.CordovaPlugin;
|
import org.apache.cordova.PluginResult;
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
|
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
|
import android.content.IntentFilter;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.PackageInfo;
|
import android.content.pm.PackageInfo;
|
||||||
import android.content.pm.PackageManager.NameNotFoundException;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.util.HashMap;
|
||||||
import java.net.URI;
|
|
||||||
import java.net.URISyntaxException;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import android.content.ActivityNotFoundException;
|
|
||||||
import android.os.Build;
|
|
||||||
import android.support.v4.content.FileProvider;
|
|
||||||
import android.util.Log;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
public class startApp extends CordovaPlugin {
|
public class startApp extends Assets {
|
||||||
|
private HashMap<Integer, BroadcastReceiver> broadcastReceiverHashMap = new HashMap<>();
|
||||||
public static final String TAG = "startApp";
|
private CallbackContext callbackContext;
|
||||||
public startApp() { }
|
|
||||||
private boolean NO_PARSE_INTENT_VALS = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes the request and returns PluginResult.
|
* Executes the request and returns PluginResult.
|
||||||
*
|
*
|
||||||
@@ -46,27 +38,86 @@ public class startApp extends CordovaPlugin {
|
|||||||
* @return Always return true.
|
* @return Always return true.
|
||||||
*/
|
*/
|
||||||
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
|
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
|
||||||
if (action.equals("start")) {
|
switch (action) {
|
||||||
this.start(args, callbackContext);
|
case "start":
|
||||||
}
|
this.start(args, callbackContext);
|
||||||
else if(action.equals("go")) {
|
break;
|
||||||
this.start(args, callbackContext);
|
case "check":
|
||||||
}
|
this.check(args, callbackContext);
|
||||||
else if(action.equals("check")) {
|
break;
|
||||||
this.check(args, callbackContext);
|
case "receiver":
|
||||||
}
|
this.receiver(args, callbackContext);
|
||||||
else if(action.equals("getExtras")) {
|
break;
|
||||||
this.getExtras(callbackContext);
|
case "unReceiver":
|
||||||
}
|
this.receiver(args, callbackContext);
|
||||||
else if(action.equals("getExtra")) {
|
break;
|
||||||
this.getExtra(args, callbackContext);
|
case "getExtras":
|
||||||
}
|
this.getExtras(callbackContext);
|
||||||
|
break;
|
||||||
|
case "getExtra":
|
||||||
|
this.getExtra(args, callbackContext);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
*
|
||||||
|
* @param args
|
||||||
|
* @param callback
|
||||||
|
*/
|
||||||
|
private void receiver(JSONArray args, CallbackContext callback) {
|
||||||
|
BroadcastReceiver receiver = new BroadcastReceiver() {
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
JSONObject result = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
result.put("_ACTION_VALUE_FORMAT_", intent.getAction());
|
||||||
|
|
||||||
|
Bundle bundle = intent.getExtras();
|
||||||
|
if (bundle != null) {
|
||||||
|
for (String key : bundle.keySet()) {
|
||||||
|
result.put(key, bundle.get(key));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, result);
|
||||||
|
pluginResult.setKeepCallback(true);
|
||||||
|
|
||||||
|
callback.sendPluginResult(pluginResult);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
JSONArray values = args.getJSONArray(0);
|
||||||
|
IntentFilter filter = new IntentFilter();
|
||||||
|
|
||||||
|
for(int i=0; i < values.length(); i++) {
|
||||||
|
filter.addAction(values.getString(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
cordova.getContext().registerReceiver(receiver, filter);
|
||||||
|
broadcastReceiverHashMap.put(receiver.hashCode(), receiver);
|
||||||
|
|
||||||
|
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, receiver.hashCode());
|
||||||
|
pluginResult.setKeepCallback(true);
|
||||||
|
|
||||||
|
callback.sendPluginResult(pluginResult);
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
callback.error("Error register receiver: " + ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
* startApp
|
* startApp
|
||||||
*/
|
*/
|
||||||
public void start(JSONArray args, CallbackContext callback) {
|
public void start(JSONArray args, CallbackContext callback) {
|
||||||
@@ -76,9 +127,7 @@ public class startApp extends CordovaPlugin {
|
|||||||
JSONArray component;
|
JSONArray component;
|
||||||
|
|
||||||
JSONObject extra;
|
JSONObject extra;
|
||||||
JSONObject key_value;
|
|
||||||
String key;
|
String key;
|
||||||
String value;
|
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@@ -89,7 +138,7 @@ public class startApp extends CordovaPlugin {
|
|||||||
/**
|
/**
|
||||||
* disable parsing intent values
|
* disable parsing intent values
|
||||||
*/
|
*/
|
||||||
if(params.has("no_parse")) {
|
if(params.has("noParseAction")) {
|
||||||
NO_PARSE_INTENT_VALS = true;
|
NO_PARSE_INTENT_VALS = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,8 +155,9 @@ public class startApp extends CordovaPlugin {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* set application
|
* set intent
|
||||||
* http://developer.android.com/reference/android/content/Intent.html (java.lang.String)
|
* http://developer.android.com/reference/android/content/Intent.html (java.lang.String)
|
||||||
*/
|
*/
|
||||||
else if(params.has("intent")) {
|
else if(params.has("intent")) {
|
||||||
@@ -157,22 +207,7 @@ public class startApp extends CordovaPlugin {
|
|||||||
* http://developer.android.com/intl/ru/reference/android/content/Intent.html#setData%28android.net.Uri%29
|
* http://developer.android.com/intl/ru/reference/android/content/Intent.html#setData%28android.net.Uri%29
|
||||||
*/
|
*/
|
||||||
if(params.has("uri")) {
|
if(params.has("uri")) {
|
||||||
String uri_str = params.getString("uri");
|
LaunchIntent.setData(Uri.parse(params.getString("uri")));
|
||||||
Uri uri = null;
|
|
||||||
if (uri_str.startsWith("file://")){
|
|
||||||
// android N surport
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
|
||||||
LaunchIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
|
||||||
try {
|
|
||||||
uri = FileProvider.getUriForFile(this.cordova.getContext(), "com.lampa.startapp.fileProvider", new File(new URI(uri_str)));
|
|
||||||
} catch (URISyntaxException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
uri = Uri.parse(uri_str);
|
|
||||||
}
|
|
||||||
LaunchIntent.setData(uri);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -208,16 +243,32 @@ public class startApp extends CordovaPlugin {
|
|||||||
|
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
key = iter.next();
|
key = iter.next();
|
||||||
|
Object value = extra.get(key);
|
||||||
value = extra.getString(key);
|
|
||||||
LaunchIntent.putExtra(parseExtraName(key), value);
|
if(value instanceof Integer) {
|
||||||
|
LaunchIntent.putExtra(parseExtraName(key), extra.getInt(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(value instanceof String) {
|
||||||
|
LaunchIntent.putExtra(parseExtraName(key), extra.getString(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(value instanceof Boolean) {
|
||||||
|
LaunchIntent.putExtra(parseExtraName(key), extra.getBoolean(key));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* launch intent
|
* launch intent
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK);
|
||||||
|
pluginResult.setKeepCallback(true);
|
||||||
|
|
||||||
if(params.has("intentstart") && "startActivityForResult".equals(params.getString("intentstart"))) {
|
if(params.has("intentstart") && "startActivityForResult".equals(params.getString("intentstart"))) {
|
||||||
|
cordova.setActivityResultCallback (this);
|
||||||
|
callbackContext = callback;
|
||||||
cordova.getActivity().startActivityForResult(LaunchIntent, 1);
|
cordova.getActivity().startActivityForResult(LaunchIntent, 1);
|
||||||
}
|
}
|
||||||
if(params.has("intentstart") && "sendBroadcast".equals(params.getString("intentstart"))) {
|
if(params.has("intentstart") && "sendBroadcast".equals(params.getString("intentstart"))) {
|
||||||
@@ -227,34 +278,22 @@ public class startApp extends CordovaPlugin {
|
|||||||
cordova.getActivity().startActivity(LaunchIntent);
|
cordova.getActivity().startActivity(LaunchIntent);
|
||||||
}
|
}
|
||||||
|
|
||||||
callback.success();
|
callback.sendPluginResult(pluginResult);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
callback.error("Incorrect params, array is not array object!");
|
callback.error("Incorrect params, array is not array object!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (JSONException e) {
|
catch (Exception 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();
|
e.printStackTrace();
|
||||||
|
callback.error(e.getClass() + ": " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* checkApp
|
* checkApp
|
||||||
*/
|
*/
|
||||||
public void check(JSONArray args, CallbackContext callback) {
|
private void check(JSONArray args, CallbackContext callback) {
|
||||||
JSONObject params;
|
JSONObject params;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -265,20 +304,16 @@ public class startApp extends CordovaPlugin {
|
|||||||
if(params.has("package")) {
|
if(params.has("package")) {
|
||||||
PackageManager pm = cordova.getActivity().getApplicationContext().getPackageManager();
|
PackageManager pm = cordova.getActivity().getApplicationContext().getPackageManager();
|
||||||
|
|
||||||
/**
|
// get package info
|
||||||
* get package info
|
|
||||||
*/
|
|
||||||
PackageInfo PackInfo = pm.getPackageInfo(params.getString("package"), PackageManager.GET_ACTIVITIES);
|
PackageInfo PackInfo = pm.getPackageInfo(params.getString("package"), PackageManager.GET_ACTIVITIES);
|
||||||
|
|
||||||
/**
|
// create json object
|
||||||
* create json object
|
JSONObject info = new JSONObject() {{
|
||||||
*/
|
put("versionName", PackInfo.versionName);
|
||||||
JSONObject info = new JSONObject();
|
put("packageName", PackInfo.packageName);
|
||||||
|
put("versionCode", PackInfo.versionCode);
|
||||||
info.put("versionName", PackInfo.versionName);
|
put("applicationInfo", PackInfo.applicationInfo);
|
||||||
info.put("packageName", PackInfo.packageName);
|
}};
|
||||||
info.put("versionCode", PackInfo.versionCode);
|
|
||||||
info.put("applicationInfo", PackInfo.applicationInfo);
|
|
||||||
|
|
||||||
callback.success(info);
|
callback.success(info);
|
||||||
}
|
}
|
||||||
@@ -289,12 +324,9 @@ public class startApp extends CordovaPlugin {
|
|||||||
else {
|
else {
|
||||||
callback.error("Incorrect params, array is not array object!");
|
callback.error("Incorrect params, array is not array object!");
|
||||||
}
|
}
|
||||||
} catch (JSONException e) {
|
|
||||||
callback.error("json: " + e.toString());
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
catch (NameNotFoundException e) {
|
catch (Exception e) {
|
||||||
callback.error("NameNotFoundException: " + e.toString());
|
callback.error(e.getClass() + ": " + e.getMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -302,7 +334,7 @@ public class startApp extends CordovaPlugin {
|
|||||||
/**
|
/**
|
||||||
* getExtras
|
* getExtras
|
||||||
*/
|
*/
|
||||||
public void getExtras(CallbackContext callback) {
|
private void getExtras(CallbackContext callback) {
|
||||||
try {
|
try {
|
||||||
Bundle extras = cordova.getActivity().getIntent().getExtras();
|
Bundle extras = cordova.getActivity().getIntent().getExtras();
|
||||||
JSONObject info = new JSONObject();
|
JSONObject info = new JSONObject();
|
||||||
@@ -324,7 +356,7 @@ public class startApp extends CordovaPlugin {
|
|||||||
/**
|
/**
|
||||||
* getExtra
|
* getExtra
|
||||||
*/
|
*/
|
||||||
public void getExtra(JSONArray args, CallbackContext callback) {
|
private void getExtra(JSONArray args, CallbackContext callback) {
|
||||||
try {
|
try {
|
||||||
String extraName = parseExtraName(args.getString(0));
|
String extraName = parseExtraName(args.getString(0));
|
||||||
Intent extraIntent = cordova.getActivity().getIntent();
|
Intent extraIntent = cordova.getActivity().getIntent();
|
||||||
@@ -333,7 +365,7 @@ public class startApp extends CordovaPlugin {
|
|||||||
String extraValue = extraIntent.getStringExtra(extraName);
|
String extraValue = extraIntent.getStringExtra(extraName);
|
||||||
|
|
||||||
if (extraValue == null) {
|
if (extraValue == null) {
|
||||||
extraValue = ((Uri) extraIntent.getParcelableExtra(extraName)).toString();
|
extraValue = (extraIntent.getParcelableExtra(extraName)).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
callback.success(extraValue);
|
callback.success(extraValue);
|
||||||
@@ -347,45 +379,30 @@ public class startApp extends CordovaPlugin {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* functions
|
|
||||||
*/
|
|
||||||
private String parseExtraName(String extraName) {
|
|
||||||
String parseIntentExtra = extraName;
|
|
||||||
|
|
||||||
try {
|
|
||||||
parseIntentExtra = getIntentValueString(extraName);
|
|
||||||
}
|
|
||||||
catch(NoSuchFieldException e) {
|
|
||||||
parseIntentExtra = extraName;
|
|
||||||
}
|
|
||||||
catch(IllegalAccessException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return extraName;
|
|
||||||
}
|
|
||||||
|
|
||||||
Log.e(TAG, parseIntentExtra);
|
|
||||||
|
|
||||||
return parseIntentExtra;
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
@Override
|
||||||
}
|
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
|
||||||
|
if(callbackContext != null) {
|
||||||
private int getIntentValue(String flag) throws NoSuchFieldException, IllegalAccessException {
|
JSONObject result = new JSONObject();
|
||||||
Field field = Intent.class.getDeclaredField(flag);
|
|
||||||
field.setAccessible(true);
|
try {
|
||||||
|
result.put("_ACTION_requestCode_", requestCode);
|
||||||
return field.getInt(null);
|
result.put("_ACTION_resultCode_", resultCode);
|
||||||
|
|
||||||
|
Bundle bundle = intent.getExtras();
|
||||||
|
if (bundle != null) {
|
||||||
|
for (String key : bundle.keySet()) {
|
||||||
|
result.put(key, bundle.get(key));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, result);
|
||||||
|
pluginResult.setKeepCallback(true);
|
||||||
|
|
||||||
|
callbackContext.sendPluginResult(pluginResult);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+34
-6
@@ -1,5 +1,6 @@
|
|||||||
|
cordova.define("com.lampa.startapp.startapp", function(require, exports, module) {
|
||||||
/**
|
/**
|
||||||
com.lampa.startapp
|
com.lampa.startapp, ver. 6.1.0
|
||||||
https://github.com/lampaa/com.lampa.startapp
|
https://github.com/lampaa/com.lampa.startapp
|
||||||
|
|
||||||
Phonegap 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).
|
||||||
@@ -29,11 +30,25 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
start: function(completeCallback, errorCallback) {
|
start: function(completeCallback, errorCallback, messageCallback) {
|
||||||
completeCallback = completeCallback || function() {};
|
completeCallback = completeCallback || function() {};
|
||||||
errorCallback = errorCallback || function() {};
|
errorCallback = errorCallback || function() {};
|
||||||
|
messageCallback = messageCallback || function() {};
|
||||||
|
|
||||||
exec(completeCallback, errorCallback, "startApp", "start", output);
|
exec(function(result) {
|
||||||
|
if(result === "OK") {
|
||||||
|
completeCallback(result);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var requestCode = result["_ACTION_requestCode_"];
|
||||||
|
delete result["_ACTION_requestCode_"];
|
||||||
|
|
||||||
|
var resultCode = result["_ACTION_resultCode_"];
|
||||||
|
delete result["_ACTION_resultCode_"];
|
||||||
|
|
||||||
|
messageCallback(result, requestCode, resultCode);
|
||||||
|
}
|
||||||
|
}, errorCallback, "startApp", "start", output);
|
||||||
},
|
},
|
||||||
check: function(completeCallback, errorCallback) {
|
check: function(completeCallback, errorCallback) {
|
||||||
completeCallback = completeCallback || function() {};
|
completeCallback = completeCallback || function() {};
|
||||||
@@ -41,11 +56,22 @@ module.exports = {
|
|||||||
|
|
||||||
exec(completeCallback, errorCallback, "startApp", "check", output);
|
exec(completeCallback, errorCallback, "startApp", "check", output);
|
||||||
},
|
},
|
||||||
go: function(completeCallback, errorCallback) {
|
receiver: function(completeCallback, errorCallback, messageCallback) {
|
||||||
completeCallback = completeCallback || function() {};
|
completeCallback = completeCallback || function() {};
|
||||||
errorCallback = errorCallback || function() {};
|
errorCallback = errorCallback || function() {};
|
||||||
|
messageCallback = messageCallback || function() {};
|
||||||
exec(completeCallback, errorCallback, "startApp", "go", output);
|
|
||||||
|
exec(function(result) {
|
||||||
|
if(/\d+/.test(result)) {
|
||||||
|
completeCallback(result);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var action = result["_ACTION_VALUE_FORMAT_"];
|
||||||
|
delete result["_ACTION_VALUE_FORMAT_"];
|
||||||
|
|
||||||
|
messageCallback(action, result);
|
||||||
|
}
|
||||||
|
}, errorCallback, "startApp", "receiver", output);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -62,3 +88,5 @@ module.exports = {
|
|||||||
this.getExtra(extraValue, completeCallback, errorCallback);
|
this.getExtra(extraValue, completeCallback, errorCallback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|||||||
@@ -1,67 +0,0 @@
|
|||||||
cordova.define("com.lampa.startapp.startapp", function(require, exports, module) {
|
|
||||||
/**
|
|
||||||
com.lampa.startapp
|
|
||||||
https://github.com/lampaa/com.lampa.startapp
|
|
||||||
|
|
||||||
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 = {
|
|
||||||
/**
|
|
||||||
* Set application params
|
|
||||||
*
|
|
||||||
* @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.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
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);
|
|
||||||
},
|
|
||||||
go: function(completeCallback, errorCallback) {
|
|
||||||
completeCallback = completeCallback || function() {};
|
|
||||||
errorCallback = errorCallback || function() {};
|
|
||||||
|
|
||||||
exec(completeCallback, errorCallback, "startApp", "go", 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
Reference in New Issue
Block a user