1
1
import { Component } from "@angular/core" ;
2
- import { android as androidApp , ios as iosApp } from "tns-core-modules/application " ;
2
+ import { Application , isAndroid , isIOS } from "@nativescript/core " ;
3
3
4
4
@Component ( {
5
5
moduleId : module . id ,
@@ -16,22 +16,22 @@ export class AppUsingAndroidExampleComponent {
16
16
public batteryLife : string ;
17
17
18
18
constructor ( ) {
19
- if ( androidApp ) {
19
+ if ( isAndroid ) {
20
20
console . log ( "We are running on Android device!" ) ;
21
21
this . isItemVisible = true ;
22
22
23
23
// >> app-class-properties
24
- // import { android as androidApp } from "tns-core-modules/application ";
25
- let isPaused = androidApp . paused ; // e.g. false
26
- let packageName = androidApp . packageName ; // The package ID e.g. org.nativescript.nativescriptsdkexamplesng
27
- let nativeApp = androidApp . nativeApp ; // The native APplication reference
28
- let foregroundActivity = androidApp . foregroundActivity ; // The current Activity reference
29
- let context = androidApp . context ; console . log ( context ) ; // The current Android context
24
+ // import { Application } from "@nativescript/core ";
25
+ let isPaused = Application . android . paused ; // e.g. false
26
+ let packageName = Application . android . packageName ; // The package ID e.g. org.nativescript.nativescriptsdkexamplesng
27
+ let nativeApp = Application . android . nativeApp ; // The native Application reference
28
+ let foregroundActivity = Application . android . foregroundActivity ; // The current Activity reference
29
+ let context = Application . android . context ; console . log ( context ) ; // The current Android context
30
30
// << app-class-properties
31
31
32
32
// >> app-android-dirs-code
33
33
this . fileList = [ ] ;
34
- this . appContext = androidApp . context ;
34
+ this . appContext = Application . android . context ;
35
35
36
36
// https://developer.android.com/reference/android/content/Context.html#getFilesDir()
37
37
this . filesDir = this . appContext . getFilesDir ( ) ;
@@ -51,7 +51,7 @@ export class AppUsingAndroidExampleComponent {
51
51
let that = this ;
52
52
53
53
// Broadcast Receiver https://developer.android.com/reference/android/content/BroadcastReceiver
54
- androidApp . registerBroadcastReceiver ( android . content . Intent . ACTION_BATTERY_CHANGED ,
54
+ Application . android . registerBroadcastReceiver ( android . content . Intent . ACTION_BATTERY_CHANGED ,
55
55
function onReceiveCallback ( androidContext : android . content . Context , intent : android . content . Intent ) {
56
56
let level = intent . getIntExtra ( android . os . BatteryManager . EXTRA_LEVEL , - 1 ) ;
57
57
let scale = intent . getIntExtra ( android . os . BatteryManager . EXTRA_SCALE , - 1 ) ;
@@ -60,15 +60,15 @@ export class AppUsingAndroidExampleComponent {
60
60
that . batteryLife = percent . toString ( ) ;
61
61
} ) ;
62
62
// << app-android-broadcast-code
63
- } else if ( iosApp ) {
63
+ } else if ( isIOS ) {
64
64
console . log ( "We are running on iOS device" ) ;
65
65
this . isItemVisible = false ;
66
66
}
67
67
}
68
68
69
69
unregister ( ) {
70
70
// >> app-android-broadcast-unregister-code
71
- androidApp . unregisterBroadcastReceiver ( android . content . Intent . ACTION_BATTERY_CHANGED ) ;
71
+ Application . android . unregisterBroadcastReceiver ( android . content . Intent . ACTION_BATTERY_CHANGED ) ;
72
72
// << app-android-broadcast-unregister-code
73
73
}
74
74
}
0 commit comments