diff --git a/app/ng-framework-modules-category/application/app-checking-target/article.md b/app/ng-framework-modules-category/application/app-checking-target/article.md index f83fd7c0..fcf385d5 100644 --- a/app/ng-framework-modules-category/application/app-checking-target/article.md +++ b/app/ng-framework-modules-category/application/app-checking-target/article.md @@ -1,4 +1,2 @@ -Use the following code in case you need to check somewhere in your code the platform you are running against: - -Basic usage of the `application` module in a component: +Basic usage of the `application` module in a component to apply different code on Android and iOS \ No newline at end of file diff --git a/app/ng-framework-modules-category/application/app-using-android-specifics/app-using-android-specifics.component.ts b/app/ng-framework-modules-category/application/app-using-android-specifics/app-using-android-specifics.component.ts index 04f57256..9c923ccb 100644 --- a/app/ng-framework-modules-category/application/app-using-android-specifics/app-using-android-specifics.component.ts +++ b/app/ng-framework-modules-category/application/app-using-android-specifics/app-using-android-specifics.component.ts @@ -20,10 +20,24 @@ export class AppUsingAndroidExampleComponent { console.log("We are running on Android device!"); this.isItemVisible = true; + // >> app-class-properties + // import { android as androidApp } from "tns-core-modules/application"; + let isPaused = androidApp.paused; // e.g. false + let packageName = androidApp.packageName; // The package ID e.g. org.nativescript.nativescriptsdkexamplesng + let nativeApp = androidApp.nativeApp; // The native APplication reference + let foregroundActivity = androidApp.foregroundActivity; // The current Activity reference + let currentContext = androidApp.currentContext; // The current Android context + let context = androidApp.context; console.log(context); // The current Android context + // << app-class-properties + // >> app-android-dirs-code this.fileList = []; this.appContext = androidApp.context; + + // https://developer.android.com/reference/android/content/Context.html#getFilesDir() this.filesDir = this.appContext.getFilesDir(); + + // https://developer.android.com/reference/android/content/Context.html#getCacheDir() this.cacheDir = this.appContext.getCacheDir(); let files = this.appContext.fileList(); @@ -37,8 +51,9 @@ export class AppUsingAndroidExampleComponent { this.batteryLife = "0"; let that = this; + // Broadcast Receiver https://developer.android.com/reference/android/content/BroadcastReceiver androidApp.registerBroadcastReceiver(android.content.Intent.ACTION_BATTERY_CHANGED, - function onReceiveCallback(context: android.content.Context, intent: android.content.Intent) { + function onReceiveCallback(androidContext: android.content.Context, intent: android.content.Intent) { let level = intent.getIntExtra(android.os.BatteryManager.EXTRA_LEVEL, -1); let scale = intent.getIntExtra(android.os.BatteryManager.EXTRA_SCALE, -1); let percent = (level / scale) * 100.0; @@ -51,6 +66,12 @@ export class AppUsingAndroidExampleComponent { this.isItemVisible = false; } } + + unregister() { + // >> app-android-broadcast-unregister-code + androidApp.unregisterBroadcastReceiver(android.content.Intent.ACTION_BATTERY_CHANGED); + // << app-android-broadcast-unregister-code + } } class File { diff --git a/app/ng-framework-modules-category/application/app-using-android-specifics/article.md b/app/ng-framework-modules-category/application/app-using-android-specifics/article.md index 90fb7c81..053279de 100644 --- a/app/ng-framework-modules-category/application/app-using-android-specifics/article.md +++ b/app/ng-framework-modules-category/application/app-using-android-specifics/article.md @@ -1,5 +1,19 @@ -Using the Android Application context to get the absolute path to Files directory: +### Application Module Android Specific Properties + +The application module provides a number of Android specific properties to access the Android app, context and activities. + + +### Using the Android Application Context + +In the extended example below, the Android context is used to get the absolute path to Files directory. +We are accessing methods from the Android SDK (like `getCacheDir` and `getFilesDir`) -Registering a Broadcast Receiver (Android) - \ No newline at end of file +### Registering a Broadcast Receiver (Android) + +NativeScript can send/receive messages and system information though broadcast receivers. +More on broadcast receivers in Android [here](https://developer.android.com/guide/components/broadcasts). + + +### Unregistering a Broadcast Receiver (Android) + \ No newline at end of file diff --git a/app/ng-framework-modules-category/application/app-using-ios-specifics/app-using-ios-specifics.component.ts b/app/ng-framework-modules-category/application/app-using-ios-specifics/app-using-ios-specifics.component.ts index c04ed624..e966149b 100644 --- a/app/ng-framework-modules-category/application/app-using-ios-specifics/app-using-ios-specifics.component.ts +++ b/app/ng-framework-modules-category/application/app-using-ios-specifics/app-using-ios-specifics.component.ts @@ -15,6 +15,19 @@ export class AppUsingIosExampleComponent { constructor() { if (iosApp) { + // >> app-class-properties-ios + // import { ios as iosApp } from "tns-core-modules/application"; + + // https://developer.apple.com/documentation/uikit/uiapplicationdelegate?language=objc + let delegate = iosApp.delegate; // the iOS application delegate + + let nativeApp = iosApp.nativeApp; // The native iOS app + + // https://developer.apple.com/documentation/uikit/uiwindow/1621581-rootviewcontroller?language=objc + let rootController = iosApp.rootController; // the iOS rootViewController + + let window = iosApp.window; // UIWindow + // << app-class-properties-ios this.isItemVisible = true; this.batteryLife = 0; diff --git a/app/ng-framework-modules-category/application/app-using-ios-specifics/article.md b/app/ng-framework-modules-category/application/app-using-ios-specifics/article.md index 63b5dcdc..864d7948 100644 --- a/app/ng-framework-modules-category/application/app-using-ios-specifics/article.md +++ b/app/ng-framework-modules-category/application/app-using-ios-specifics/article.md @@ -1,5 +1,10 @@ -Adding a Notification Observer (iOS) +### Application Module iOS Specific Properties + +The application module provides a number of iOS specific properties to access the iOS app, delegate and root view controller, etc.. + + +### Adding a Notification Observer (iOS) -Removing a notification observer +### Removing a notification observer