當前位置: 首頁>>代碼示例>>Java>>正文


Java Intent.ACTION_POWER_DISCONNECTED屬性代碼示例

本文整理匯總了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));
}
 
開發者ID:PrivacyStreams,項目名稱:PrivacyStreams,代碼行數:76,代碼來源:DeviceEventUpdatesProvider.java

示例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;
}
 
開發者ID:SShineTeam,項目名稱:Huochexing12306,代碼行數:7,代碼來源:ChargeProtector.java

示例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);
    }
}
 
開發者ID:Rai220,項目名稱:Telephoto,代碼行數:35,代碼來源:BatteryReceiver.java

示例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 );
    }
}
 
開發者ID:guardianproject,項目名稱:haven,代碼行數:29,代碼來源:PowerConnectionReceiver.java


注:本文中的android.content.Intent.ACTION_POWER_DISCONNECTED屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。