本文整理汇总了Java中android.content.Intent.ACTION_POWER_DISCONNECTED属性的典型用法代码示例。如果您正苦于以下问题:Java Intent.ACTION_POWER_DISCONNECTED属性的具体用法?Java Intent.ACTION_POWER_DISCONNECTED怎么用?Java Intent.ACTION_POWER_DISCONNECTED使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.content.Intent
的用法示例。
在下文中一共展示了Intent.ACTION_POWER_DISCONNECTED属性的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onReceive
@Override
public void onReceive(Context context, Intent intent) {
String event = null;
String type = null;
switch(intent.getAction()){
case Intent.ACTION_SCREEN_OFF:
event = DeviceEvent.EVENT_SCREEN_OFF;
type = DeviceEvent.TYPE_SCREEN;
break;
case Intent.ACTION_SCREEN_ON:
event = DeviceEvent.EVENT_SCREEN_ON;
type = DeviceEvent.TYPE_SCREEN;
break;
case Intent.ACTION_USER_PRESENT:
event = DeviceEvent.EVENT_SCREEN_USER_PRESENT;
type = DeviceEvent.TYPE_SCREEN;
break;
case Intent.ACTION_BOOT_COMPLETED:
event = DeviceEvent.EVENT_BOOT_COMPLETED;
type = DeviceEvent.TYPE_BOOT;
break;
case Intent.ACTION_SHUTDOWN:
event = DeviceEvent.EVENT_BOOT_SHUTDOWN;
type = DeviceEvent.TYPE_BOOT;
break;
case Intent.ACTION_BATTERY_LOW:
event = DeviceEvent.EVENT_BATTERY_LOW;
type = DeviceEvent.TYPE_BATTERY;
break;
case Intent.ACTION_BATTERY_OKAY:
event = DeviceEvent.EVENT_BATTERY_OKAY;
type = DeviceEvent.TYPE_BATTERY;
break;
case Intent.ACTION_POWER_CONNECTED:
event = DeviceEvent.EVENT_BATTERY_AC_CONNECTED;
type = DeviceEvent.TYPE_BATTERY;
break;
case Intent.ACTION_POWER_DISCONNECTED:
event = DeviceEvent.EVENT_BATTERY_AC_DISCONNECTED;
type = DeviceEvent.TYPE_BATTERY;
break;
case AudioManager.RINGER_MODE_CHANGED_ACTION:
AudioManager am = (AudioManager)getContext().getSystemService(Context.AUDIO_SERVICE);
switch (am.getRingerMode()) {
case AudioManager.RINGER_MODE_SILENT:
event = DeviceEvent.EVENT_RINGER_SILENT;
type = DeviceEvent.TYPE_RINGER;
break;
case AudioManager.RINGER_MODE_VIBRATE:
event = DeviceEvent.EVENT_RINGER_VIBRATE;
type = DeviceEvent.TYPE_RINGER;
break;
case AudioManager.RINGER_MODE_NORMAL:
event = DeviceEvent.EVENT_RINGER_NORMAL;
type = DeviceEvent.TYPE_RINGER;
break;
}
default:
break;
}
if (type != null)
output(new DeviceEvent(type, event));
}
示例2: start
@Override
public boolean start(Object obj) {
mReceiver = new ChargeBroadcastReceiver();
IntentFilter filter = new IntentFilter(Intent.ACTION_POWER_DISCONNECTED);
getmServiceContext().registerReceiver(mReceiver, filter);
return true;
}
示例3: onReceive
@Override
public void onReceive(Context context, Intent intent) {
String message = null;
switch (intent.getAction()) {
case Intent.ACTION_BATTERY_LOW:
if (!isSentBatteryLow) {
message = botService.getString(R.string.battery_low);
isSentBatteryLow = true;
}
break;
case Intent.ACTION_BATTERY_OKAY:
isSentBatteryLow = false;
break;
case Intent.ACTION_POWER_DISCONNECTED:
message = botService.getString(R.string.power_disconnected) + getStatus();
break;
case Intent.ACTION_POWER_CONNECTED:
message = botService.getString(R.string.power_connected);
break;
case Intent.ACTION_BATTERY_CHANGED:
mBatteryLevel = getBatteryLevel(intent);
mPowerStatus = getBatteryStatus(intent);
ReceiverStorage.getInstance().setBatteryLevel(mBatteryLevel);
int segment = getSegment(mBatteryLevel);
if (segment < lastSegmentNotify) {
String attention = mIsCharging ? botService.getString(R.string.battery_discharging) : "";
message = attention + getStatus();
}
lastSegmentNotify = segment;
break;
}
if (message != null) {
botService.getTelegramService().sendMessageToAll(message);
}
}
示例4: onReceive
@Override
public void onReceive(Context context, Intent intent) {
// Can't use intent.getIntExtra(BatteryManager.EXTRA_STATUS), as the extra is not provided.
// The code example at
// https://developer.android.com/training/monitoring-device-state/battery-monitoring.html
// is wrong
// see https://stackoverflow.com/questions/10211609/problems-with-action-power-connected
// explicitly check the intent action
// avoids lint issue UnsafeProtectedBroadcastReceiver
boolean isCharging;
if(intent.getAction() == null) return;
switch(intent.getAction()){
case Intent.ACTION_POWER_CONNECTED:
isCharging = true;
break;
case Intent.ACTION_POWER_DISCONNECTED:
isCharging = false;
break;
default:
return;
}
if (MonitorService.getInstance() != null
&& MonitorService.getInstance().isRunning()) {
MonitorService.getInstance().alert(EventTrigger.POWER, context.getString(R.string.status_charging) + isCharging );
}
}