forked from hypery2k/nativescript-urlhandler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
urlhandler.android.ts
44 lines (40 loc) · 1.69 KB
/
urlhandler.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
import * as application from 'application';
import { getCallback, extractAppURL } from './urlhandler.common';
export { handleOpenURL } from './urlhandler.common';
let lastReceivedData = null;
export function handleIntent(intent: any) {
let data = intent.getData();
if (lastReceivedData === null || data.toString() !== lastReceivedData.toString()) {
try {
if (new String(intent.getAction()).valueOf() === new String(android.content.Intent.ACTION_MAIN).valueOf()
|| new String(intent.getAction()).valueOf() === new String(android.content.Intent.ACTION_VIEW).valueOf()) {
try {
setTimeout(() => getCallback()(extractAppURL(data)));
} catch (ignored) {
application.android.on(application.AndroidApplication.activityResultEvent, (eventData) => {
setTimeout(() => getCallback()(extractAppURL(data)));
});
}
}
} catch (e) {
console.error('Unknown error during getting App URL data', e);
}
lastReceivedData = data;
}
}
application.android.on(application.AndroidApplication.activityCreatedEvent, (args) => {
let intent: android.content.Intent = args.activity.getIntent();
try {
handleIntent(intent);
} catch (e) {
console.error('Unknown error during getting App URL data', e);
}
});
application.android.on(application.AndroidApplication.activityResumedEvent, (args) => {
let intent: android.content.Intent = args.activity.getIntent();
try {
handleIntent(intent);
} catch (e) {
console.error('Unknown error during getting App URL data', e);
}
});