-
-
Save codeforfun-jp/3d9080378025eefb1e08e2f6bdfe5fe6 to your computer and use it in GitHub Desktop.
Android Studio Battery Checker 2-4
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) { | |
/* 省略 */ | |
if (action != null && action.equals(Intent.ACTION_BATTERY_CHANGED)) { | |
/* 省略 */ | |
// 画像を表示 | |
if (percentage >= 90) { | |
batteryImage.setImageResource(R.drawable.b100); | |
} else if (percentage >= 65) { | |
batteryImage.setImageResource(R.drawable.b75); | |
} else if (percentage >= 40) { | |
batteryImage.setImageResource(R.drawable.b50); | |
} else if (percentage >= 15) { | |
batteryImage.setImageResource(R.drawable.b25); | |
} else { | |
batteryImage.setImageResource(R.drawable.b0); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment