Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// >> application-require
import * as app from "tns-core-modules/application";
import * as platform from "tns-core-modules/platform";
// << application-require
// >> application-app-check
if (app.android) {
console.log("We are running on Android device!");
} else if (app.ios) {
console.log("We are running on iOS device");
}
// << application-app-check
import * as TKUnit from "../TKUnit";
export var testInitialized = function () {
if (platform.device.os === platform.platformNames.android) {
// we have the android defined
TKUnit.assert(app.android, "Application module not properly intialized");
} else if (platform.device.os === platform.platformNames.ios) {
TKUnit.assert(app.ios, "Application module not properly intialized");
}
}
resolve({
deepLink: deepLinkUri === null ? null : deepLinkUri.toString(),
matchType: deepLinkUri === null ? null : 1,
invitationId: firebaseAppInvite.getInvitationId() // string | null
});
}
});
const onFailureListener = new com.google.android.gms.tasks.OnFailureListener({
onFailure: exception => {
reject(exception.getMessage());
}
});
firebaseDynamicLinks.getDynamicLink(appModule.android.startActivity.getIntent())
.addOnSuccessListener(onSuccessListener)
.addOnFailureListener(onFailureListener);
} catch (ex) {
console.log("Error in firebase.getInvitation: " + ex);
reject(ex);
}
});
};
Bluetooth._coarseLocationPermissionGranted = function () {
var hasPermission = android.os.Build.VERSION.SDK_INT < 23; // Android M. (6.0)
if (!hasPermission) {
hasPermission = android.content.pm.PackageManager.PERMISSION_GRANTED ==
android.support.v4.content.ContextCompat.checkSelfPermission(application.android.foregroundActivity, android.Manifest.permission.ACCESS_COARSE_LOCATION);
}
return hasPermission;
};
// RESULT_OK = -1
if (args.resultCode === android.app.Activity.RESULT_OK) {
this.sendEvent(Bluetooth.bluetooth_enabled_event);
resolve(true);
} else {
resolve(false);
}
} catch (ex) {
CLog(CLogTypes.error, ex);
application.android.off(application.AndroidApplication.activityResultEvent, onBluetoothEnableResult);
this.sendEvent(Bluetooth.error_event, { error: ex }, `Bluetooth.enable ---- error: ${ex}`);
reject(ex);
return;
}
} else {
application.android.off(application.AndroidApplication.activityResultEvent, onBluetoothEnableResult);
resolve(false);
return;
}
};
export function setStatusBarColors() {
// Make the iOS status bar transparent with white text
if (application.ios) {
application.on("launch", () => UIApplication.sharedApplication.setStatusBarStyleAnimated(UIStatusBarStyle.LightContent, true));
}
// Make the Android status bar transparent
if (application.android) {
// TODO make sure this works when --uglify'd, otherwise use "activityStarted"
application.android.on(application.AndroidApplication.activityStartedEvent, (data: application.AndroidActivityEventData) => {
if (application.android && device.sdkVersion >= "21") {
let View = android.view.View;
let window = application.android.startActivity.getWindow();
window.setStatusBarColor(0x000000);
let decorView = window.getDecorView();
decorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
// | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
}
});
}
public static SUCCESS_MSG(): string {
let msg = `Your plugin is working on ${app.android ? 'Android' : 'iOS'}.`;
setTimeout(() => {
dialogs.alert(`${msg} For real. It's really working :)`).then(() => console.log(`Dialog closed.`));
}, 2000);
return msg;
}
}
ngOnInit() {
if (application.ios) {
this.isAndroid = false;
this.isIos = true;
} else if (application.android) {
this.isAndroid = true;
this.isIos = false;
}
}
}
_cleanAttachmentFolder() {
if (application.android.context) {
let dir = application.android.context.getExternalCacheDir();
let storage = dir.toString() + "/filecomposer";
let cacheFolder = fs.Folder.fromPath(storage);
cacheFolder.clear();
}
}
toStringArray(arg) {
return new Promise((resolve, reject) => {
try {
let popupMenu = new android.widget.PopupMenu(
app.android.foregroundActivity,
options.view.android
);
if (options.actions[0] !== undefined) {
if (Types.isString(options.actions[0])) {
for (let i = 0; i < options.actions.length; i++) {
const action = options.actions[i];
popupMenu.getMenu().add(action);
}
popupMenu.setOnMenuItemClickListener(
new android.widget.PopupMenu.OnMenuItemClickListener({
onMenuItemClick: (item): boolean => {
resolve({
id: options.actions.indexOf(item.getTitle()),
title: item.getTitle()
export function getLayout(id: string) {
if (!id) {
return 0;
}
const context: android.content.Context = application.android.context;
return context.getResources().getIdentifier(id, 'layout', context.getPackageName());
}