-
-
Save codingwithsara/d3b02129efbea31d12629265dddb448d to your computer and use it in GitHub Desktop.
Java (Android Studio) Tutorial - Battery Checker -
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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