import { Component } from "@angular/core" ; import { Application , isAndroid , isIOS } from "@nativescript/core" ; @ Component ( { moduleId : module . id , templateUrl : "./app-using-android-specifics.component.html" } ) export class AppUsingAndroidExampleComponent { private appContext : any ; public isItemVisible : boolean ; public filesDir : string ; public cacheDir : string ; public fileList : Array < string > ; public batteryLife : string ; constructor ( ) { if ( isAndroid ) { console . log ( "We are running on Android device!" ) ; this . isItemVisible = true ; let isPaused = Application . android . paused ; let packageName = Application . android . packageName ; let nativeApp = Application . android . nativeApp ; let foregroundActivity = Application . android . foregroundActivity ; let context = Application . android . context ; console . log ( context ) ; this . fileList = [ ] ; this . appContext = Application . android . context ; this . filesDir = this . appContext . getFilesDir ( ) ; this . cacheDir = this . appContext . getCacheDir ( ) ; let files = this . appContext . fileList ( ) ; for ( let index = 0 ; index < files . length ; index ++ ) { let element = files [ index ] ; this . fileList . push ( element . toString ( ) ) ; } this . batteryLife = "0" ; let that = this ; Application . android . registerBroadcastReceiver ( android . content . Intent . ACTION_BATTERY_CHANGED , function onReceiveCallback ( androidContext , 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 ; that . batteryLife = percent . toString ( ) ; } ) ; } else if ( isIOS ) { console . log ( "We are running on iOS device" ) ; this . isItemVisible = false ; } } unregister ( ) { Application . android . unregisterBroadcastReceiver ( android . content . Intent . ACTION_BATTERY_CHANGED ) ; } } class File { constructor ( public name ) { } }