Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Java (Android Studio) Tutorial - Battery Checker -
package com.codingwithsara.batterychecker;
import android.content.Intent;
import android.content.IntentFilter;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
private BatteryReceiver mBatteryReceiver = new BatteryReceiver();
private IntentFilter mIntentFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
protected void onResume() {
super.onResume();
registerReceiver(mBatteryReceiver, mIntentFilter);
}
@Override
protected void onPause() {
unregisterReceiver(mBatteryReceiver);
super.onPause();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment