-
Notifications
You must be signed in to change notification settings - Fork 120
/
startApp.js
89 lines (77 loc) · 2.71 KB
/
startApp.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/**
com.lampa.startapp, ver. 6.1.4
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, messageCallback) {
completeCallback = completeCallback || function() {};
errorCallback = errorCallback || function() {};
messageCallback = messageCallback || function() {};
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) {
completeCallback = completeCallback || function() {};
errorCallback = errorCallback || function() {};
exec(completeCallback, errorCallback, "startApp", "check", output);
},
receiver: function(completeCallback, errorCallback, messageCallback) {
completeCallback = completeCallback || function() {};
errorCallback = errorCallback || function() {};
messageCallback = messageCallback || function() {};
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);
}
}
},
/**
* 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);
}
}