Java Code Examples for android.content.Intent.ACTION_BATTERY_LOW

The following are Jave code examples for showing how to use ACTION_BATTERY_LOW of the android.content.Intent class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: PrivacyStreams   File: DeviceEventUpdatesProvider.java   View Source Code Vote up 9 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 2
Project: Telephoto   File: BatteryReceiver.java   View Source Code Vote up 6 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
Project: DeviceInfo   File: BatteryFragment.java   View Source Code Vote up 6 votes
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_battery, container, false);
    unbinder = ButterKnife.bind(this, view);

    IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
    mActivity.registerReceiver(mBatInfoReceiver, filter);
    IntentFilter filter2 = new IntentFilter(Intent.ACTION_BATTERY_LOW);
    mActivity.registerReceiver(mBatLow, filter2);
    return view;
}