一部のリスナーを使用して、アプリケーションのバッテリーレベルと電源接続を制御しようとしていますが、何らかの理由で、アプリケーションの開始時にも更新されません。手動で行う方法はありますか?
クラス PhoneStatusService
private BroadcastReceiver mPowerConnectedReceiver;
private BroadcastReceiver mPowerDisconnectedReceiver;
private BroadcastReceiver mNormalPowerReceiver;
private BroadcastReceiver mLowPowerReceiver;
private static boolean sIsBatteryCharging = false;
private static boolean sIsBatteryLevelOk = true;
onCreate()
mPowerConnectedReceiver = new BroadcastReceiver() {
@Override
public void onReceive(final Context context, final Intent intent) {
PhoneStatusService.this.setChargingStatus(true);
}
};
mPowerDisconnectedReceiver = new BroadcastReceiver() {
@Override
public void onReceive(final Context context, final Intent intent) {
PhoneStatusService.this.setChargingStatus(false);
}
};
mNormalPowerReceiver = new BroadcastReceiver() {
@Override
public void onReceive(final Context context, final Intent intent) {
PhoneStatusService.this.setBatteryLevel(true);
}
};
mLowPowerReceiver = new BroadcastReceiver() {
@Override
public void onReceive(final Context context, final Intent intent) {
PhoneStatusService.this.setBatteryLevel(false);
}
};
this.registerReceiver(mPowerConnectedReceiver, new IntentFilter(
Intent.ACTION_POWER_CONNECTED));
this.registerReceiver(mPowerDisconnectedReceiver, new IntentFilter(
Intent.ACTION_POWER_DISCONNECTED));
this.registerReceiver(mNormalPowerReceiver, new IntentFilter(Intent.ACTION_BATTERY_OKAY));
this.registerReceiver(mLowPowerReceiver, new IntentFilter(Intent.ACTION_BATTERY_LOW));