-
-
Save codeforfun-jp/47f70d41bbb285d335da41dadde09999 to your computer and use it in GitHub Desktop.
Android Studio Battery Checker 2-1
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
public class BatteryReceiver extends BroadcastReceiver { | |
@Override | |
public void onReceive(Context context, Intent intent) { | |
TextView statusLabel = ((MainActivity)context).findViewById(R.id.statusLabel); | |
TextView percentageLabel = ((MainActivity)context).findViewById(R.id.percentageLabel); | |
ImageView batteryImage = ((MainActivity)context).findViewById(R.id.batteryImage); | |
String action = intent.getAction(); | |
if (action != null && action.equals(Intent.ACTION_BATTERY_CHANGED)) { | |
// バッテリー情報を取得 | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment