@aigens/aigens-sdk-core 0.0.7 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AigensAigensSdkCore.podspec +1 -1
- package/README.md +60 -0
- package/android/src/main/AndroidManifest.xml +9 -0
- package/android/src/main/java/com/aigens/sdk/WebContainerActivity.java +195 -7
- package/android/src/main/java/com/aigens/sdk/plugins/CorePlugin.java +120 -8
- package/dist/docs.json +58 -0
- package/dist/esm/definitions.d.ts +12 -0
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +12 -0
- package/dist/esm/web.js +21 -0
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +21 -0
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +21 -0
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/CorePlugin.m +4 -0
- package/ios/Plugin/CorePlugin.swift +69 -16
- package/ios/Plugin/WebContainer.swift +83 -0
- package/ios/Plugin/WebContainer.xib +113 -0
- package/ios/Plugin/WebContainerViewController.swift +227 -17
- package/package.json +4 -1
@@ -10,7 +10,7 @@ Pod::Spec.new do |s|
|
|
10
10
|
s.homepage = package['repository']['url']
|
11
11
|
s.author = package['author']
|
12
12
|
s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
|
13
|
-
s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
|
13
|
+
s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp,xib}'
|
14
14
|
s.ios.deployment_target = '12.0'
|
15
15
|
s.dependency 'Capacitor'
|
16
16
|
s.swift_version = '5.1'
|
package/README.md
CHANGED
@@ -17,7 +17,11 @@ npx cap sync
|
|
17
17
|
* [`dismiss(...)`](#dismiss)
|
18
18
|
* [`finish(...)`](#finish)
|
19
19
|
* [`getMember(...)`](#getmember)
|
20
|
+
* [`getDeeplink(...)`](#getdeeplink)
|
20
21
|
* [`openBrowser(...)`](#openbrowser)
|
22
|
+
* [`isInstalledApp(...)`](#isinstalledapp)
|
23
|
+
* [`getIsProductionEnvironment()`](#getisproductionenvironment)
|
24
|
+
* [`openExternalUrl(...)`](#openexternalurl)
|
21
25
|
|
22
26
|
</docgen-index>
|
23
27
|
|
@@ -84,6 +88,21 @@ getMember(options: any) => Promise<any>
|
|
84
88
|
--------------------
|
85
89
|
|
86
90
|
|
91
|
+
### getDeeplink(...)
|
92
|
+
|
93
|
+
```typescript
|
94
|
+
getDeeplink(options: any) => Promise<any>
|
95
|
+
```
|
96
|
+
|
97
|
+
| Param | Type |
|
98
|
+
| ------------- | ---------------- |
|
99
|
+
| **`options`** | <code>any</code> |
|
100
|
+
|
101
|
+
**Returns:** <code>Promise<any></code>
|
102
|
+
|
103
|
+
--------------------
|
104
|
+
|
105
|
+
|
87
106
|
### openBrowser(...)
|
88
107
|
|
89
108
|
```typescript
|
@@ -98,4 +117,45 @@ openBrowser(options: any) => Promise<any>
|
|
98
117
|
|
99
118
|
--------------------
|
100
119
|
|
120
|
+
|
121
|
+
### isInstalledApp(...)
|
122
|
+
|
123
|
+
```typescript
|
124
|
+
isInstalledApp(options: { key: string; }) => Promise<{ install: boolean; }>
|
125
|
+
```
|
126
|
+
|
127
|
+
| Param | Type |
|
128
|
+
| ------------- | ----------------------------- |
|
129
|
+
| **`options`** | <code>{ key: string; }</code> |
|
130
|
+
|
131
|
+
**Returns:** <code>Promise<{ install: boolean; }></code>
|
132
|
+
|
133
|
+
--------------------
|
134
|
+
|
135
|
+
|
136
|
+
### getIsProductionEnvironment()
|
137
|
+
|
138
|
+
```typescript
|
139
|
+
getIsProductionEnvironment() => Promise<{ isPrd: boolean; }>
|
140
|
+
```
|
141
|
+
|
142
|
+
**Returns:** <code>Promise<{ isPrd: boolean; }></code>
|
143
|
+
|
144
|
+
--------------------
|
145
|
+
|
146
|
+
|
147
|
+
### openExternalUrl(...)
|
148
|
+
|
149
|
+
```typescript
|
150
|
+
openExternalUrl(options: { url: string; }) => Promise<any>
|
151
|
+
```
|
152
|
+
|
153
|
+
| Param | Type |
|
154
|
+
| ------------- | ----------------------------- |
|
155
|
+
| **`options`** | <code>{ url: string; }</code> |
|
156
|
+
|
157
|
+
**Returns:** <code>Promise<any></code>
|
158
|
+
|
159
|
+
--------------------
|
160
|
+
|
101
161
|
</docgen-api>
|
@@ -1,3 +1,12 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
1
2
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
2
3
|
package="com.aigens.sdk">
|
4
|
+
<uses-permission android:name="android.permission.INTERNET" />
|
5
|
+
<application android:hardwareAccelerated="true">
|
6
|
+
<activity android:name=".WebContainerActivity"
|
7
|
+
android:screenOrientation="portrait"
|
8
|
+
>
|
9
|
+
|
10
|
+
</activity>
|
11
|
+
</application>
|
3
12
|
</manifest>
|
@@ -1,11 +1,18 @@
|
|
1
1
|
package com.aigens.sdk;
|
2
2
|
|
3
|
+
import android.app.Activity;
|
3
4
|
import android.content.Intent;
|
4
5
|
import android.content.res.AssetManager;
|
5
6
|
import android.graphics.Bitmap;
|
7
|
+
import android.graphics.Color;
|
6
8
|
import android.net.Uri;
|
9
|
+
import android.os.Build;
|
7
10
|
import android.os.Bundle;
|
11
|
+
import android.text.TextUtils;
|
12
|
+
import android.util.Log;
|
8
13
|
import android.view.View;
|
14
|
+
import android.webkit.ServiceWorkerClient;
|
15
|
+
import android.webkit.ServiceWorkerController;
|
9
16
|
import android.webkit.WebResourceError;
|
10
17
|
import android.webkit.WebResourceRequest;
|
11
18
|
import android.webkit.WebResourceResponse;
|
@@ -21,7 +28,6 @@ import com.getcapacitor.CapConfig;
|
|
21
28
|
import com.getcapacitor.Plugin;
|
22
29
|
import com.getcapacitor.PluginLoadException;
|
23
30
|
import com.getcapacitor.PluginManager;
|
24
|
-
import com.aigens.sdk.R;
|
25
31
|
|
26
32
|
import org.json.JSONException;
|
27
33
|
import org.json.JSONObject;
|
@@ -40,6 +46,18 @@ public class WebContainerActivity extends BridgeActivity {
|
|
40
46
|
private String url;
|
41
47
|
private boolean navbar = false;
|
42
48
|
private Map member;
|
49
|
+
private Map deeplink;
|
50
|
+
private boolean ENVIRONMENT_PRODUCTION = true;
|
51
|
+
private List<String> externalProtocols = new ArrayList<String>(){{
|
52
|
+
add("octopus://");
|
53
|
+
add("alipay://");
|
54
|
+
add("alipays://");
|
55
|
+
add("alipayhk://");
|
56
|
+
add("tel:");
|
57
|
+
add("mailto:");
|
58
|
+
add("payme://");
|
59
|
+
add("https://play.google.com");
|
60
|
+
}};
|
43
61
|
|
44
62
|
private void debug(Object... msgs){
|
45
63
|
|
@@ -59,7 +77,9 @@ public class WebContainerActivity extends BridgeActivity {
|
|
59
77
|
|
60
78
|
super.onCreate(savedInstanceState);
|
61
79
|
|
62
|
-
setContentView(R.layout.sdk_layout_main);
|
80
|
+
setContentView(com.aigens.sdk.R.layout.sdk_layout_main);
|
81
|
+
|
82
|
+
|
63
83
|
|
64
84
|
Intent intent = getIntent();
|
65
85
|
this.url = intent.getStringExtra("url");
|
@@ -68,10 +88,23 @@ public class WebContainerActivity extends BridgeActivity {
|
|
68
88
|
this.navbar = intent.getBooleanExtra("navbar", false);
|
69
89
|
|
70
90
|
this.member = (Map) intent.getSerializableExtra("member");
|
91
|
+
this.deeplink = (Map) intent.getSerializableExtra("deeplink");
|
92
|
+
boolean ENVIRONMENT_PRODUCTION = intent.getBooleanExtra("ENVIRONMENT_PRODUCTION", true);
|
93
|
+
CorePlugin.setENVIRONMENT_PRODUCTION(ENVIRONMENT_PRODUCTION);
|
94
|
+
|
95
|
+
List<String> externalProtocols_ = (List<String>) intent.getSerializableExtra("externalProtocols");
|
96
|
+
if (externalProtocols_ != null) {
|
97
|
+
for (String s : externalProtocols_) {
|
98
|
+
this.externalProtocols.add(s);
|
99
|
+
}
|
100
|
+
}
|
71
101
|
|
72
102
|
if(this.member != null) {
|
73
103
|
CorePlugin.setMember(this.member);
|
74
104
|
}
|
105
|
+
if (this.deeplink != null) {
|
106
|
+
CorePlugin.setDeeplink(this.deeplink);
|
107
|
+
}
|
75
108
|
|
76
109
|
System.out.println("OPEN URL:"+ url);
|
77
110
|
|
@@ -82,6 +115,9 @@ public class WebContainerActivity extends BridgeActivity {
|
|
82
115
|
if(member != null){
|
83
116
|
debug("member", member);
|
84
117
|
}
|
118
|
+
if(member != null){
|
119
|
+
debug("deeplink", deeplink);
|
120
|
+
}
|
85
121
|
|
86
122
|
JSONObject config = readConfig();
|
87
123
|
|
@@ -119,6 +155,16 @@ public class WebContainerActivity extends BridgeActivity {
|
|
119
155
|
|
120
156
|
}
|
121
157
|
|
158
|
+
addExtraPlugins(new String[] {
|
159
|
+
"com.aigens.googlepay.GooglePayPlugin",
|
160
|
+
"com.aigens.octopus.OctopusPlugin",
|
161
|
+
"com.aigens.wechatpay.WechatPayPlugin",
|
162
|
+
"com.aigens.alipay.AliPayPlugin",
|
163
|
+
"com.aigens.alipayhk.AliPayhkPlugin",
|
164
|
+
"com.aigens.payme.PaymePlugin",
|
165
|
+
}, plugins);
|
166
|
+
addExtraPlugins(intent.getStringArrayExtra("extraClasspaths"), plugins);
|
167
|
+
|
122
168
|
debug("App plugins:" + plugins);
|
123
169
|
|
124
170
|
super.init(savedInstanceState, plugins, cc);
|
@@ -126,10 +172,45 @@ public class WebContainerActivity extends BridgeActivity {
|
|
126
172
|
//still have time to override webview client to avoid any intercept
|
127
173
|
|
128
174
|
BypassWebViewClient wvc = new BypassWebViewClient(this.bridge);
|
175
|
+
wvc.activity = this;
|
176
|
+
wvc.externalProtocols = this.externalProtocols;
|
129
177
|
this.bridge.getWebView().setWebViewClient(wvc);
|
178
|
+
this.bridge.getWebView().setWebContentsDebuggingEnabled(true);
|
179
|
+
|
180
|
+
// this.bridge.getWebView().getSettings().setAppCacheEnabled(false);
|
181
|
+
// this.bridge.getWebView().clearCache(true);
|
182
|
+
// this.bridge.getWebView().clearHistory();
|
183
|
+
// this.bridge.getWebView().clearFormData();
|
184
|
+
// this.bridge.getWebView().getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
|
130
185
|
|
131
186
|
initView();
|
132
187
|
initLayout(false, true, false);
|
188
|
+
|
189
|
+
disableServiceWorker(this.url, this.bridge);
|
190
|
+
}
|
191
|
+
|
192
|
+
private void addExtraPlugins(String[] extraClasspaths, List<Class<? extends Plugin>> plugins) {
|
193
|
+
if (extraClasspaths == null) return;
|
194
|
+
for (int i = 0; i < extraClasspaths.length; i++) {
|
195
|
+
String classPath = extraClasspaths[i];
|
196
|
+
try {
|
197
|
+
Class<?> c = Class.forName(classPath);
|
198
|
+
Class<? extends Plugin> sub = c.asSubclass(Plugin.class);
|
199
|
+
String clsName = sub.getName();
|
200
|
+
Boolean add = false;
|
201
|
+
for (Class<? extends Plugin> plugin : plugins) {
|
202
|
+
if (plugin.getName().equals(clsName)) {
|
203
|
+
add = true;
|
204
|
+
break;
|
205
|
+
}
|
206
|
+
}
|
207
|
+
if (!add) {
|
208
|
+
plugins.add(sub);
|
209
|
+
}
|
210
|
+
} catch (ClassNotFoundException e) {
|
211
|
+
e.printStackTrace();
|
212
|
+
}
|
213
|
+
}
|
133
214
|
}
|
134
215
|
|
135
216
|
private void initView(){
|
@@ -154,6 +235,8 @@ public class WebContainerActivity extends BridgeActivity {
|
|
154
235
|
}
|
155
236
|
});
|
156
237
|
|
238
|
+
setTheme();
|
239
|
+
|
157
240
|
}
|
158
241
|
|
159
242
|
private void reload(){
|
@@ -170,6 +253,18 @@ public class WebContainerActivity extends BridgeActivity {
|
|
170
253
|
|
171
254
|
}
|
172
255
|
|
256
|
+
private void setTheme() {
|
257
|
+
Intent intent = getIntent();
|
258
|
+
String themeColor = intent.getStringExtra("themeColor");
|
259
|
+
if (!TextUtils.isEmpty(themeColor)) {
|
260
|
+
View info = findViewById(R.id.info);
|
261
|
+
View error = findViewById(R.id.error);
|
262
|
+
info.setBackgroundColor(Color.parseColor(themeColor));
|
263
|
+
error.setBackgroundColor(Color.parseColor(themeColor));
|
264
|
+
bridge.getWebView().setBackgroundColor(Color.parseColor(themeColor));
|
265
|
+
getWindow().setStatusBarColor(Color.parseColor(themeColor));//set statussbar color
|
266
|
+
}
|
267
|
+
}
|
173
268
|
private void initLayout(boolean showWeb, boolean showInfo, boolean showError){
|
174
269
|
|
175
270
|
if(showError){
|
@@ -203,6 +298,30 @@ public class WebContainerActivity extends BridgeActivity {
|
|
203
298
|
return plugins;
|
204
299
|
}
|
205
300
|
|
301
|
+
private static boolean SW_DISABLED = false;
|
302
|
+
|
303
|
+
private static void disableServiceWorker(String originUrl, Bridge bridge){
|
304
|
+
|
305
|
+
if(SW_DISABLED) return;
|
306
|
+
|
307
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
308
|
+
ServiceWorkerController.getInstance().setServiceWorkerClient(new ServiceWorkerClient() {
|
309
|
+
@Override
|
310
|
+
public WebResourceResponse shouldInterceptRequest(WebResourceRequest request) {
|
311
|
+
|
312
|
+
// Fixed: Sometimes the plugin cannot be loaded
|
313
|
+
String currentUrl = request.getUrl().toString();
|
314
|
+
if (currentUrl.equals(originUrl)) {
|
315
|
+
return bridge.getLocalServer().shouldInterceptRequest(request);
|
316
|
+
}
|
317
|
+
return null;
|
318
|
+
}
|
319
|
+
});
|
320
|
+
}
|
321
|
+
|
322
|
+
SW_DISABLED = true;
|
323
|
+
|
324
|
+
}
|
206
325
|
|
207
326
|
|
208
327
|
private static String readString(InputStream is) throws IOException {
|
@@ -254,10 +373,78 @@ public class WebContainerActivity extends BridgeActivity {
|
|
254
373
|
//BridgeWebViewClient
|
255
374
|
class BypassWebViewClient extends BridgeWebViewClient {
|
256
375
|
|
376
|
+
public Activity activity;
|
377
|
+
private String TAG = "BypassWebViewClient";
|
378
|
+
List<String> externalProtocols;
|
257
379
|
public BypassWebViewClient(Bridge bridge) {
|
258
380
|
super(bridge);
|
259
381
|
}
|
260
382
|
|
383
|
+
public boolean loopExternalProtocols(String url) {
|
384
|
+
if (externalProtocols != null) {
|
385
|
+
for (String p : externalProtocols) {
|
386
|
+
if (url != null && url != "" && url.startsWith(p)) {
|
387
|
+
return true;
|
388
|
+
}
|
389
|
+
}
|
390
|
+
}
|
391
|
+
return false;
|
392
|
+
}
|
393
|
+
public boolean shouldOverrideUrl(WebView view, String url) {
|
394
|
+
if (url.startsWith(WebView.SCHEME_TEL)) {
|
395
|
+
try {
|
396
|
+
Intent intent = new Intent(Intent.ACTION_DIAL);
|
397
|
+
intent.setData(Uri.parse(url));
|
398
|
+
activity.startActivity(intent);
|
399
|
+
return true;
|
400
|
+
} catch (android.content.ActivityNotFoundException e) {
|
401
|
+
Log.e(TAG, "Error dialing " + url + ": " + e.toString());
|
402
|
+
}
|
403
|
+
} else if (url.startsWith("geo:") || url.startsWith(WebView.SCHEME_MAILTO) || url.startsWith("market:")
|
404
|
+
|| loopExternalProtocols(url)) {
|
405
|
+
try {
|
406
|
+
Intent intent = new Intent(Intent.ACTION_VIEW);
|
407
|
+
intent.setData(Uri.parse(url));
|
408
|
+
activity.startActivity(intent);
|
409
|
+
return true;
|
410
|
+
} catch (android.content.ActivityNotFoundException e) {
|
411
|
+
Log.e(TAG, "Error with " + url + ": " + e.toString());
|
412
|
+
}
|
413
|
+
}
|
414
|
+
// If sms:5551212?body=This is the message
|
415
|
+
else if (url.startsWith("sms:")) {
|
416
|
+
try {
|
417
|
+
Intent intent = new Intent(Intent.ACTION_VIEW);
|
418
|
+
|
419
|
+
// Get address
|
420
|
+
String address = null;
|
421
|
+
int parmIndex = url.indexOf('?');
|
422
|
+
if (parmIndex == -1) {
|
423
|
+
address = url.substring(4);
|
424
|
+
} else {
|
425
|
+
address = url.substring(4, parmIndex);
|
426
|
+
|
427
|
+
// If body, then set sms body
|
428
|
+
Uri uri = Uri.parse(url);
|
429
|
+
String query = uri.getQuery();
|
430
|
+
if (query != null) {
|
431
|
+
if (query.startsWith("body=")) {
|
432
|
+
intent.putExtra("sms_body", query.substring(5));
|
433
|
+
}
|
434
|
+
}
|
435
|
+
}
|
436
|
+
intent.setData(Uri.parse("sms:" + address));
|
437
|
+
intent.putExtra("address", address);
|
438
|
+
intent.setType("vnd.android-dir/mms-sms");
|
439
|
+
activity.startActivity(intent);
|
440
|
+
return true;
|
441
|
+
} catch (android.content.ActivityNotFoundException e) {
|
442
|
+
Log.e(TAG, "Error sending sms " + url + ":" + e.toString());
|
443
|
+
}
|
444
|
+
}
|
445
|
+
return false;
|
446
|
+
}
|
447
|
+
|
261
448
|
//somehow this must call parent, otherwise plugins won't work
|
262
449
|
@Override
|
263
450
|
public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
|
@@ -267,7 +454,9 @@ public class WebContainerActivity extends BridgeActivity {
|
|
267
454
|
//debug("shouldInterceptRequest", url);
|
268
455
|
|
269
456
|
|
270
|
-
|
457
|
+
|
458
|
+
//support redirect from /scan
|
459
|
+
if(url.indexOf("/scan?") > 0 || url.indexOf("/qr?") > 0 || url.indexOf("//scan") > 0){
|
271
460
|
return null;
|
272
461
|
}
|
273
462
|
|
@@ -281,11 +470,10 @@ public class WebContainerActivity extends BridgeActivity {
|
|
281
470
|
@Override
|
282
471
|
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
|
283
472
|
debug("shouldOverrideUrlLoading", request.getUrl());
|
284
|
-
|
473
|
+
Uri url = request.getUrl();
|
285
474
|
|
286
475
|
//return super.shouldOverrideUrlLoading(view, request);
|
287
|
-
|
288
|
-
return false;
|
476
|
+
return shouldOverrideUrl(view, url.toString());
|
289
477
|
}
|
290
478
|
|
291
479
|
@Override
|
@@ -295,7 +483,7 @@ public class WebContainerActivity extends BridgeActivity {
|
|
295
483
|
|
296
484
|
//return super.shouldOverrideUrlLoading(view, url);
|
297
485
|
|
298
|
-
return
|
486
|
+
return shouldOverrideUrl(view, url);
|
299
487
|
}
|
300
488
|
|
301
489
|
@Override
|
@@ -2,11 +2,16 @@ package com.aigens.sdk.plugins;
|
|
2
2
|
|
3
3
|
import android.app.Activity;
|
4
4
|
import android.content.Intent;
|
5
|
+
import android.content.pm.PackageInfo;
|
6
|
+
import android.content.pm.PackageManager;
|
7
|
+
import android.net.Uri;
|
8
|
+
import android.os.Parcelable;
|
5
9
|
|
6
10
|
import androidx.activity.result.ActivityResultLauncher;
|
7
11
|
import androidx.appcompat.app.AppCompatActivity;
|
8
12
|
|
9
13
|
import com.aigens.sdk.WebContainerActivity;
|
14
|
+
import com.getcapacitor.JSArray;
|
10
15
|
import com.getcapacitor.JSObject;
|
11
16
|
import com.getcapacitor.Plugin;
|
12
17
|
import com.getcapacitor.PluginCall;
|
@@ -18,6 +23,8 @@ import org.json.JSONException;
|
|
18
23
|
import java.io.Serializable;
|
19
24
|
import java.util.HashMap;
|
20
25
|
import java.util.Iterator;
|
26
|
+
import java.util.List;
|
27
|
+
import java.util.Locale;
|
21
28
|
import java.util.Map;
|
22
29
|
|
23
30
|
@CapacitorPlugin(name = "Core")
|
@@ -26,21 +33,30 @@ public class CorePlugin extends Plugin {
|
|
26
33
|
public static boolean DEBUG = false;
|
27
34
|
|
28
35
|
private static Map member;
|
36
|
+
private static Map deeplink;
|
37
|
+
private static boolean ENVIRONMENT_PRODUCTION = true;
|
38
|
+
private void debug(Object msg) {
|
29
39
|
|
30
|
-
|
31
|
-
|
32
|
-
if(DEBUG){
|
40
|
+
if (DEBUG) {
|
33
41
|
System.out.println(msg);
|
34
42
|
}
|
35
43
|
|
36
44
|
}
|
37
45
|
|
38
|
-
public static void setMember(Map member){
|
46
|
+
public static void setMember(Map member) {
|
39
47
|
CorePlugin.member = member;
|
40
48
|
}
|
41
49
|
|
50
|
+
public static void setDeeplink(Map deeplink) {
|
51
|
+
CorePlugin.deeplink = deeplink;
|
52
|
+
}
|
53
|
+
|
54
|
+
public static void setENVIRONMENT_PRODUCTION(boolean ENVIRONMENT_PRODUCTION) {
|
55
|
+
CorePlugin.ENVIRONMENT_PRODUCTION = ENVIRONMENT_PRODUCTION;
|
56
|
+
}
|
57
|
+
|
42
58
|
@Override
|
43
|
-
protected void handleOnStart(){
|
59
|
+
protected void handleOnStart() {
|
44
60
|
|
45
61
|
}
|
46
62
|
|
@@ -65,6 +81,25 @@ public class CorePlugin extends Plugin {
|
|
65
81
|
call.resolve(ret);
|
66
82
|
}
|
67
83
|
|
84
|
+
@PluginMethod()
|
85
|
+
public void getDeeplink(PluginCall call) {
|
86
|
+
|
87
|
+
debug("CorePlugin getDeeplink:" + deeplink);
|
88
|
+
|
89
|
+
JSObject ret = new JSObject();
|
90
|
+
ret.put("deeplink", deeplink);
|
91
|
+
call.resolve(ret);
|
92
|
+
}
|
93
|
+
|
94
|
+
@PluginMethod()
|
95
|
+
public void getIsProductionEnvironment(PluginCall call) {
|
96
|
+
|
97
|
+
debug("CorePlugin getIsProductionEnvironment:" + ENVIRONMENT_PRODUCTION);
|
98
|
+
JSObject ret = new JSObject();
|
99
|
+
ret.put("isPrd", ENVIRONMENT_PRODUCTION);
|
100
|
+
call.resolve(ret);
|
101
|
+
}
|
102
|
+
|
68
103
|
|
69
104
|
// Launch
|
70
105
|
//public void onButtonClick(View view) {
|
@@ -90,16 +125,20 @@ public class CorePlugin extends Plugin {
|
|
90
125
|
|
91
126
|
String url = call.getString("url");
|
92
127
|
|
93
|
-
if(url == null) return;
|
128
|
+
if (url == null) return;
|
94
129
|
|
95
130
|
JSObject options = call.getObject("options", null);
|
96
131
|
JSObject member = call.getObject("member", null);
|
132
|
+
JSObject deeplink = call.getObject("deeplink", null);
|
133
|
+
boolean ENVIRONMENT_PRODUCTION = call.getBoolean("ENVIRONMENT_PRODUCTION", true);
|
134
|
+
CorePlugin.setENVIRONMENT_PRODUCTION(ENVIRONMENT_PRODUCTION);
|
97
135
|
|
98
136
|
Map memMap = new HashMap();
|
137
|
+
Map deeplinkMap = new HashMap();
|
99
138
|
|
100
|
-
if(member != null){
|
139
|
+
if (member != null) {
|
101
140
|
Iterator<String> iter = member.keys();
|
102
|
-
while(iter.hasNext()){
|
141
|
+
while (iter.hasNext()) {
|
103
142
|
String k = iter.next();
|
104
143
|
try {
|
105
144
|
Object v = member.get(k);
|
@@ -110,13 +149,38 @@ public class CorePlugin extends Plugin {
|
|
110
149
|
|
111
150
|
}
|
112
151
|
}
|
152
|
+
if (deeplinkMap != null) {
|
153
|
+
Iterator<String> iter = deeplink.keys();
|
154
|
+
while (iter.hasNext()) {
|
155
|
+
String k = iter.next();
|
156
|
+
try {
|
157
|
+
Object v = deeplink.get(k);
|
158
|
+
deeplinkMap.put(k, v);
|
159
|
+
} catch (JSONException e) {
|
160
|
+
e.printStackTrace();
|
161
|
+
}
|
162
|
+
}
|
163
|
+
}
|
113
164
|
|
114
165
|
Activity act = getActivity();
|
115
166
|
|
116
167
|
Intent intent = new Intent(act, WebContainerActivity.class);
|
117
168
|
|
169
|
+
JSArray externalProtocols = call.getArray("externalProtocols");
|
170
|
+
try {
|
171
|
+
if (externalProtocols != null) {
|
172
|
+
List<String> es = externalProtocols.toList();
|
173
|
+
intent.putExtra("externalProtocols", (Serializable) es);
|
174
|
+
}
|
175
|
+
} catch (JSONException e) {
|
176
|
+
e.printStackTrace();
|
177
|
+
}
|
178
|
+
|
118
179
|
intent.putExtra("url", url);
|
119
180
|
intent.putExtra("member", (Serializable) memMap);
|
181
|
+
intent.putExtra("deeplink", (Serializable) deeplinkMap);
|
182
|
+
intent.putExtra("ENVIRONMENT_PRODUCTION", ENVIRONMENT_PRODUCTION);
|
183
|
+
|
120
184
|
|
121
185
|
act.startActivity(intent);
|
122
186
|
|
@@ -125,4 +189,52 @@ public class CorePlugin extends Plugin {
|
|
125
189
|
call.resolve(ret);
|
126
190
|
}
|
127
191
|
|
192
|
+
@PluginMethod
|
193
|
+
public void openExternalUrl(PluginCall call) {
|
194
|
+
String url = call.getString("url");
|
195
|
+
if (url == null) {
|
196
|
+
call.reject("missing the url");
|
197
|
+
return;
|
198
|
+
}
|
199
|
+
|
200
|
+
final Intent intentExternal = new Intent();
|
201
|
+
intentExternal.setAction(Intent.ACTION_VIEW);
|
202
|
+
intentExternal.setData(Uri.parse(url));
|
203
|
+
Activity act = getActivity();
|
204
|
+
act.startActivity(intentExternal);
|
205
|
+
JSObject ret = new JSObject();
|
206
|
+
ret.put("open", true);
|
207
|
+
call.resolve(ret);
|
208
|
+
}
|
209
|
+
|
210
|
+
@PluginMethod
|
211
|
+
public void isInstalledApp(PluginCall call) {
|
212
|
+
String packname = call.getString("key");
|
213
|
+
Activity act = getActivity();
|
214
|
+
if (packname == null) {
|
215
|
+
call.reject("key is missing or is invaild key");
|
216
|
+
return;
|
217
|
+
}
|
218
|
+
|
219
|
+
try {
|
220
|
+
JSObject object = new JSObject();
|
221
|
+
final PackageManager packageManager = act.getPackageManager();// 获取packagemanager
|
222
|
+
List<PackageInfo> pinfo = packageManager.getInstalledPackages(0);// 获取所有已安装程序的包信息
|
223
|
+
object.put("install", false);
|
224
|
+
if (pinfo != null && packname != null) {
|
225
|
+
packname = packname.toLowerCase(Locale.ENGLISH);
|
226
|
+
for (int i = 0; i < pinfo.size(); i++) {
|
227
|
+
String pn = pinfo.get(i).packageName.toLowerCase(Locale.ENGLISH);
|
228
|
+
if (pn.equals(packname)) {
|
229
|
+
object.put("install", true);
|
230
|
+
}
|
231
|
+
}
|
232
|
+
}
|
233
|
+
call.resolve(object);
|
234
|
+
} catch (Exception e) {
|
235
|
+
e.printStackTrace();
|
236
|
+
call.reject("key is missing or is invaild key");
|
237
|
+
}
|
238
|
+
}
|
239
|
+
|
128
240
|
}
|
package/dist/docs.json
CHANGED
@@ -69,6 +69,22 @@
|
|
69
69
|
"complexTypes": [],
|
70
70
|
"slug": "getmember"
|
71
71
|
},
|
72
|
+
{
|
73
|
+
"name": "getDeeplink",
|
74
|
+
"signature": "(options: any) => Promise<any>",
|
75
|
+
"parameters": [
|
76
|
+
{
|
77
|
+
"name": "options",
|
78
|
+
"docs": "",
|
79
|
+
"type": "any"
|
80
|
+
}
|
81
|
+
],
|
82
|
+
"returns": "Promise<any>",
|
83
|
+
"tags": [],
|
84
|
+
"docs": "",
|
85
|
+
"complexTypes": [],
|
86
|
+
"slug": "getdeeplink"
|
87
|
+
},
|
72
88
|
{
|
73
89
|
"name": "openBrowser",
|
74
90
|
"signature": "(options: any) => Promise<any>",
|
@@ -84,6 +100,48 @@
|
|
84
100
|
"docs": "",
|
85
101
|
"complexTypes": [],
|
86
102
|
"slug": "openbrowser"
|
103
|
+
},
|
104
|
+
{
|
105
|
+
"name": "isInstalledApp",
|
106
|
+
"signature": "(options: { key: string; }) => Promise<{ install: boolean; }>",
|
107
|
+
"parameters": [
|
108
|
+
{
|
109
|
+
"name": "options",
|
110
|
+
"docs": "",
|
111
|
+
"type": "{ key: string; }"
|
112
|
+
}
|
113
|
+
],
|
114
|
+
"returns": "Promise<{ install: boolean; }>",
|
115
|
+
"tags": [],
|
116
|
+
"docs": "",
|
117
|
+
"complexTypes": [],
|
118
|
+
"slug": "isinstalledapp"
|
119
|
+
},
|
120
|
+
{
|
121
|
+
"name": "getIsProductionEnvironment",
|
122
|
+
"signature": "() => Promise<{ isPrd: boolean; }>",
|
123
|
+
"parameters": [],
|
124
|
+
"returns": "Promise<{ isPrd: boolean; }>",
|
125
|
+
"tags": [],
|
126
|
+
"docs": "",
|
127
|
+
"complexTypes": [],
|
128
|
+
"slug": "getisproductionenvironment"
|
129
|
+
},
|
130
|
+
{
|
131
|
+
"name": "openExternalUrl",
|
132
|
+
"signature": "(options: { url: string; }) => Promise<any>",
|
133
|
+
"parameters": [
|
134
|
+
{
|
135
|
+
"name": "options",
|
136
|
+
"docs": "",
|
137
|
+
"type": "{ url: string; }"
|
138
|
+
}
|
139
|
+
],
|
140
|
+
"returns": "Promise<any>",
|
141
|
+
"tags": [],
|
142
|
+
"docs": "",
|
143
|
+
"complexTypes": [],
|
144
|
+
"slug": "openexternalurl"
|
87
145
|
}
|
88
146
|
],
|
89
147
|
"properties": []
|