forked from ludwiktrammer/nativescript-open-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
open-app.android.js
30 lines (29 loc) · 1.06 KB
/
open-app.android.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
"use strict";
var utils = require("utils/utils");
function openApp(appID, storeFallback, appleStoreId, queries) {
if (storeFallback === void 0) { storeFallback = true; }
var context = utils.ad.getApplicationContext();
var Intent = android.content.Intent;
var intent = context.getPackageManager().getLaunchIntentForPackage(appID);
if (intent) {
// Open app
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//Append Query
if(queries != null && queries.length > 0){
for(var x in queries){
intent.putExtra(queries[x]['key'], queries[x]['value']);
}
}
context.startActivity(intent);
return true;
}
else if (storeFallback) {
// Can't open app - open store
intent = new Intent(Intent.ACTION_VIEW);
intent.setData(android.net.Uri.parse("https://play.google.com/store/apps/details?id=" + appID));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
return false;
}
exports.openApp = openApp;