Java Code Examples for android.content.Intent#ACTION_POWER_CONNECTED
The following examples show how to use
android.content.Intent#ACTION_POWER_CONNECTED .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CustomReceiver.java From Android-Developer-Fundamentals-Version-2 with GNU General Public License v3.0 | 6 votes |
@Override public void onReceive(Context context, Intent intent) { String intentAction = intent.getAction(); if (intentAction != null) { String toastMessage = context.getResources().getString(R.string.unknown_intent_action); switch (intentAction){ case Intent.ACTION_POWER_CONNECTED: toastMessage = context.getResources().getString(R.string.power_connected); break; case Intent.ACTION_POWER_DISCONNECTED: toastMessage = context.getResources().getString(R.string.power_disconnected); break; case ACTION_CUSTOM_BROADCAST: toastMessage = context.getResources().getString(R.string.custom_broadcast_received); break; } Toast.makeText(context, toastMessage, Toast.LENGTH_LONG).show(); } }
Example 2
Source File: BatteryReceiver.java From Telephoto with Apache License 2.0 | 5 votes |
@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); } }
Example 3
Source File: MonitorService.java From haven with GNU General Public License v3.0 | 5 votes |
private void startSensors () { mIsMonitoringActive = true; // set current event start date in prefs mPrefs.setCurrentSession(new Date(System.currentTimeMillis())); if (!mPrefs.getAccelerometerSensitivity().equals(PreferenceManager.OFF)) { mAccelManager = new AccelerometerMonitor(this); if(Build.VERSION.SDK_INT>=18) { mBumpMonitor = new BumpMonitor(this); } } //moving these out of the accelerometer pref, but need to enable off prefs for them too mBaroMonitor = new BarometerMonitor(this); mLightMonitor = new AmbientLightMonitor(this); mPrefs.activateMonitorService(true); if (mPrefs.getHeartbeatActive()){ SignalSender sender = SignalSender.getInstance(this, mPrefs.getSignalUsername()); sender.startHeartbeatTimer(mPrefs.getHeartbeatNotificationTimeMs()); } // && !mPrefs.getVideoMonitoringActive() if (!mPrefs.getMicrophoneSensitivity().equals(PreferenceManager.OFF)) mMicMonitor = new MicrophoneMonitor(this); mPowerReceiver = new PowerConnectionReceiver(); // register our power status receivers IntentFilter powerConnectedFilter = new IntentFilter(Intent.ACTION_POWER_CONNECTED); registerReceiver(mPowerReceiver, powerConnectedFilter); IntentFilter powerDisconnectedFilter = new IntentFilter(Intent.ACTION_POWER_DISCONNECTED); registerReceiver(mPowerReceiver, powerDisconnectedFilter); }
Example 4
Source File: PowerConnectionReceiver.java From haven with GNU General Public License v3.0 | 5 votes |
@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 if(intent.getAction() == null) return; switch(intent.getAction()){ case Intent.ACTION_POWER_CONNECTED: break; case Intent.ACTION_POWER_DISCONNECTED: break; default: return; } if (MonitorService.getInstance() != null && MonitorService.getInstance().isRunning()) { MonitorService.getInstance().alert(EventTrigger.POWER, Utils.getBatteryPercentage(context) + "%" + " \n" + context.getString(R.string.power_source_status) + " " + getBatteryStatus(context)); } }
Example 5
Source File: PowerTracker.java From Easer with GNU General Public License v3.0 | 5 votes |
@Override public void onReceive(Context context, Intent intent) { switch (intent.getAction()) { case Intent.ACTION_POWER_CONNECTED: determineAndNotify(true); break; case Intent.ACTION_POWER_DISCONNECTED: determineAndNotify(false); break; } }
Example 6
Source File: PowerSlot.java From Easer with GNU General Public License v3.0 | 5 votes |
@Override public void onReceive(Context context, Intent intent) { switch (intent.getAction()) { case Intent.ACTION_POWER_CONNECTED: determineAndNotify(true); break; case Intent.ACTION_POWER_DISCONNECTED: determineAndNotify(false); break; } }
Example 7
Source File: BatteryReceiver.java From DevUtils with Apache License 2.0 | 4 votes |
@Override public void onReceive(Context context, Intent intent) { try { String action = intent.getAction(); // 打印当前触发的广播 LogPrintUtils.dTag(TAG, "onReceive Action: " + action); // 获取当前电量, 范围是 0-100 int level = intent.getIntExtra("level", 0); // 判断类型 switch (action) { case Intent.ACTION_BATTERY_CHANGED: // 电量状态发送改变 if (sListener != null) { sListener.onBatteryChanged(level); } break; case Intent.ACTION_BATTERY_LOW: // 电量低 if (sListener != null) { sListener.onBatteryLow(level); } break; case Intent.ACTION_BATTERY_OKAY: // 电量从低变回高通知 if (sListener != null) { sListener.onBatteryOkay(level); } break; case Intent.ACTION_POWER_CONNECTED: // 连接充电器 if (sListener != null) { sListener.onPowerConnected(level, true); } break; case Intent.ACTION_POWER_DISCONNECTED: // 断开充电器 if (sListener != null) { sListener.onPowerConnected(level, false); } break; case Intent.ACTION_POWER_USAGE_SUMMARY: // 电力使用情况总结 if (sListener != null) { sListener.onPowerUsageSummary(level); } break; } } catch (Exception e) { LogPrintUtils.eTag(TAG, e, "onReceive"); } }
Example 8
Source File: DeviceEventUpdatesProvider.java From PrivacyStreams with Apache License 2.0 | 4 votes |
@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)); }
Example 9
Source File: BatteryMonitor.java From talkback with Apache License 2.0 | 4 votes |
@Override public void onReceive(Context context, Intent intent) { if ((telephonyManager != null) && (telephonyManager.getCallState() != TelephonyManager.CALL_STATE_IDLE)) { return; } final String action = intent.getAction(); if (action == null) { return; } String announcement = null; switch (action) { case Intent.ACTION_BATTERY_CHANGED: int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0); int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, 100); batteryLevel = (scale > 0 ? Math.round(level / (float) scale * 100) : -1); break; case Intent.ACTION_POWER_DISCONNECTED: // Announces the battery level only when we have updated battery level information. if (batteryLevel == -1) { announcement = this.context.getString( R.string.template_charging_lite, this.context.getString(R.string.notification_type_status_stopped)); } else { announcement = this.context.getString( R.string.template_charging, this.context.getString(R.string.notification_type_status_stopped), String.valueOf(batteryLevel)); } break; case Intent.ACTION_POWER_CONNECTED: if (batteryLevel == -1) { announcement = this.context.getString( R.string.template_charging_lite, this.context.getString(R.string.notification_type_status_started)); } else { announcement = this.context.getString( R.string.template_charging, this.context.getString(R.string.notification_type_status_started), String.valueOf(batteryLevel)); } break; } if (announcement != null) { EventId eventId = EVENT_ID_UNTRACKED; // Not a user-initiated event. speechController.speak( announcement, /* Text */ SpeechController.QUEUE_MODE_INTERRUPT, /* QueueMode */ FeedbackItem.FLAG_NO_HISTORY | FeedbackItem.FLAG_FORCED_FEEDBACK_AUDIO_PLAYBACK_ACTIVE | FeedbackItem.FLAG_FORCED_FEEDBACK_MICROPHONE_ACTIVE, /* Flags */ null, /* SpeechParams */ eventId); } }