diff --git a/client/Nightr/src/app/app.component.ts b/client/Nightr/src/app/app.component.ts index ffe906e..954da50 100644 --- a/client/Nightr/src/app/app.component.ts +++ b/client/Nightr/src/app/app.component.ts @@ -31,7 +31,7 @@ export class AppComponent { return this.cameraService.takePicture(). then(picture => { this.image = JSON.stringify(picture); - console.log('this is picture in json', JSON.stringify(picture)); + //console.log('this is picture in json', JSON.stringify(picture)); this.getLocation(); }) } @@ -39,7 +39,7 @@ export class AppComponent { public getLocation(): any { this.geoLocationService.getLocation().then(location => { this.locationData = location; - console.log('this is locationData', this.locationData); + //console.log('this is locationData', this.locationData); this.submit(); }).catch(error => { }); diff --git a/client/Nightr/src/app/services/my-battery-info.service.ts b/client/Nightr/src/app/services/my-battery-info.service.ts index 21800ea..424327f 100644 --- a/client/Nightr/src/app/services/my-battery-info.service.ts +++ b/client/Nightr/src/app/services/my-battery-info.service.ts @@ -1,16 +1,22 @@ import { Injectable } from '@angular/core'; -import * as power from 'nativescript-powerinfo' +import { android as androidApp, ios as iosApp } from "tns-core-modules/application"; +import { ios as iosUtils } from "tns-core-modules/utils/utils"; @Injectable({ providedIn: 'root' }) export class MyBatteryInfoService { - constructor() { } - /* public getPowerPercent (): number { - power.startPowerUpdates(function(Info) { - power.stopPowerUpdates(); - return Info.percentage; - }) - } */ + public getBatteryLife() { + if (iosApp){ + iosUtils.getter(UIDevice, UIDevice.currentDevice).batteryMonitoringEnabled = true; + let battery = +(iosUtils.getter(UIDevice, UIDevice.currentDevice).batteryLevel * 100); + }else{ + androidApp.registerBroadcastReceiver(android.content.Intent.ACTION_BATTERY_CHANGED,(context: 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; + }); + } +} }