-
배터리 충전 여부 확인 메소드안드로이드(스튜디오)/막 써 2018. 6. 15. 14:14반응형
/**
* 배터리 충전 중 여부 반환.
* @param context {@link Context}
* @return true : 충전 중, false : 충전 중 아님
*/
public static boolean isBatteryCharging(Context context){
Intent intentBattery = context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
int status = intentBattery.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
boolean isCharging = false;
if(status == BatteryManager.BATTERY_STATUS_CHARGING || status == BatteryManager.BATTERY_STATUS_FULL){
isCharging = true;
}else if(status == BatteryManager.BATTERY_STATUS_NOT_CHARGING || status == BatteryManager.BATTERY_STATUS_DISCHARGING){
isCharging = false;
}
return isCharging;
}반응형'안드로이드(스튜디오) > 막 써' 카테고리의 다른 글
release apk 빌드시 Could not find com.android.tools.lint:lint-gradle:xx.x.x. 오류 (0) 2018.07.25 서비스 실행 중 여부 확인 메소드 (0) 2018.07.18 배터리 잔량 가져오기 메소드 (0) 2018.06.15 저장소 경로 가져오기 메소드 (0) 2018.04.06 디바이스 전화번호 가져오기 메소드 (1) 2018.04.05