2

i'm connecting Ionic cordova to my physical device with USB and command : ionic cordova run android --livereload.

Thats the using this code to get the BatteryStatus:

export class HomePage {
  batterystatus$: number;
  subscription : any;
  constructor(private batteryStatus: BatteryStatus, public navCtrl: NavController) {

  }

  ionViewDidLoad() {
    alert('ionViewDidLoad BatteryStatus');
    // watch change in battery status
    this.subscription = this.batteryStatus.onChange().subscribe(
      (status: BatteryStatusResponse) => {
        this.batterystatus$ = status.level;
        console.log(status.level, status.isPlugged);
      }
    );

    // stop watch

  }
  ionViewWillLeave() {
    this.subscription.unsubscribe();
  }

}
<ion-header>
  <ion-navbar>
    <ion-title>Home</ion-title>
  </ion-navbar>
</ion-header>

<ion-content padding>
  <h2>Welcome to Ionic!</h2>
  {{subscription}}
  {{ batterystatus$}}
  bbbbbb
  <p>
    This starter project comes with simple tabs-based layout for apps
    that are going to primarily use a Tabbed UI.
  </p>
  <p>
    Take a look at the <code>src/pages/</code> directory to add or change tabs,
    update any existing page or create new pages.
  </p>
</ion-content>

The problem: When i start the app by the first time, it shows the current BatteryLevel on my view. As livereload is activated when i make a change to de code it "Builds..." the app with my change, but then the current BatteryLevel don't appear anymore.

The Other Problem: When i leave the app with the first start, without making changes to the code so the app don't build it doesn't send changes changes of the battery level to the variable, it keeps static.

Bruno Cerk
  • 355
  • 3
  • 16

0 Answers0