This repository has been archived by the owner on Dec 14, 2023. It is now read-only.
/
wxapi.WXEntryActivity.android.ts
93 lines (71 loc) · 2.76 KB
/
wxapi.WXEntryActivity.android.ts
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
90
91
92
93
import { setActivityCallbacks, AndroidActivityCallbacks } from "tns-core-modules/ui/frame";
import * as app from "tns-core-modules/application";
import { AndroidActivityEventData } from "tns-core-modules/application";
import * as appSettings from "tns-core-modules/application-settings";
declare var androidx, com;
// It should be YourAPPId.wxapi.WXEntryActivity
@JavaProxy("YOUR_APP_ID.wxapi.WXEntryActivity")
@Interfaces([com.tencent.mm.opensdk.openapi.IWXAPIEventHandler])
class WXEntryActivity extends androidx.appcompat.app.AppCompatActivity {
public isNativeScriptActivity;
private _callbacks: AndroidActivityCallbacks;
private api;
public onCreate(savedInstanceState): void {
this.isNativeScriptActivity = true;
if (!this._callbacks) {
setActivityCallbacks(this);
}
let appID = appSettings.getString("WECHAT_APP_ID");
this.api = com.tencent.mm.opensdk.openapi.WXAPIFactory.createWXAPI(this, appID, false);
try {
this.api.handleIntent(this.getIntent(), this);
} catch (e) {
console.log("handleIntent error");
console.log(e);
}
this._callbacks.onCreate(this, savedInstanceState, this.getIntent(), super.onCreate);
}
public onNewIntent(intent) {
super.onNewIntent(intent);
this.setIntent(intent);
try {
this.api.handleIntent(intent, this);
} catch (e) {
console.log("handleIntent error");
console.log(e);
}
}
public onResp(res) {
setTimeout(() => {
app.notify({
eventName: 'wxApiResponse',
object: res,
activity: this
});
}, 500);
}
public onReq(res) {
//console.log("onReq");
}
public onSaveInstanceState(outState): void {
this._callbacks.onSaveInstanceState(this, outState, super.onSaveInstanceState);
}
public onStart(): void {
this._callbacks.onStart(this, super.onStart);
}
public onStop(): void {
this._callbacks.onStop(this, super.onStop);
}
public onDestroy(): void {
this._callbacks.onDestroy(this, super.onDestroy);
}
public onBackPressed(): void {
this._callbacks.onBackPressed(this, super.onBackPressed);
}
public onRequestPermissionsResult(requestCode: number, permissions: Array<string>, grantResults: Array<number>): void {
this._callbacks.onRequestPermissionsResult(this, requestCode, permissions, grantResults, undefined /*TODO: Enable if needed*/);
}
public onActivityResult(requestCode: number, resultCode: number, data): void {
this._callbacks.onActivityResult(this, requestCode, resultCode, data, super.onActivityResult);
}
}