Skip to content

Instantly share code, notes, and snippets.

@codingwithsara
Created September 20, 2020 05:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codingwithsara/d3b02129efbea31d12629265dddb448d to your computer and use it in GitHub Desktop.
Save codingwithsara/d3b02129efbea31d12629265dddb448d to your computer and use it in GitHub Desktop.
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