Example usage for android.content Intent ACTION_BATTERY_OKAY

List of usage examples for android.content Intent ACTION_BATTERY_OKAY

Introduction

In this page you can find the example usage for android.content Intent ACTION_BATTERY_OKAY.

Prototype

String ACTION_BATTERY_OKAY

To view the source code for android.content Intent ACTION_BATTERY_OKAY.

Click Source Link

Document

Broadcast Action: Indicates the battery is now okay after being low.

Usage

From source file:org.alpine_toolkit.AlpineToolkitService.java

@Override
public void onCreate() {
    Log.i(LOG_TAG, "onCreate");
    super.onCreate();

    if (m_battery_receiver == null) { // Fixme: ???
        m_battery_receiver = new BatteryReceiver();
        IntentFilter intent_filter = new IntentFilter();
        intent_filter.addAction(Intent.ACTION_BATTERY_CHANGED);
        intent_filter.addAction(Intent.ACTION_POWER_CONNECTED);
        intent_filter.addAction(Intent.ACTION_POWER_DISCONNECTED);
        intent_filter.addAction(Intent.ACTION_BATTERY_LOW);
        intent_filter.addAction(Intent.ACTION_BATTERY_OKAY);
        registerReceiver(m_battery_receiver, intent_filter);
    }// w  w  w  . ja  v a2s .com
}

From source file:pl.zajecia.cw3.MainService.java

/**
 * Registers other receivers, which receiving doesn't
 * mean changing wallpaper./*ww w  .  j a  va  2 s.  c o  m*/
 */
private void registerOtherReceivers() {

    if (mDisableOnBatteryLow) {
        IntentFilter i = new IntentFilter();
        i.addAction(Intent.ACTION_BATTERY_LOW);
        i.addAction(Intent.ACTION_BATTERY_OKAY);
        registerReceiver(mBatteryChangeBroadcastReceiver, i);
    }
}

From source file:pl.zajecia.cw3.MainService.java

/**
 * Handles battery state change broadcast,
 * like stopping receiver when battery low.
 *
 * @param intent the intent//  w ww .j av a2  s .  c  o m
 */
private void handleBatteryChange(Intent intent) {
    if (intent.getAction() == Intent.ACTION_BATTERY_LOW) {
        if (mDisableOnBatteryLow) {
            unregisterReceiver(mAlarmBroadcastReceiver);
        }
    } else if (intent.getAction() == Intent.ACTION_BATTERY_OKAY) {
        if (!mAlarmBroadcastReceiverEnabled) {
            registerAlarmReceiver();
        }
    }
}

From source file:org.deviceconnect.android.deviceplugin.host.HostDeviceService.java

@Override
public int onStartCommand(final Intent intent, final int flags, final int startId) {

    if (intent == null) {
        return START_STICKY;
    }/*from  w ww. j  a va  2s. c o  m*/

    String action = intent.getAction();

    if (Intent.ACTION_BATTERY_CHANGED.equals(action) || Intent.ACTION_BATTERY_LOW.equals(action)
            || Intent.ACTION_BATTERY_OKAY.equals(action)) {
        // ????

        mHostBatteryManager.setBatteryRequest(intent);

        List<Event> events = EventManager.INSTANCE.getEventList(mDeviceId, HostBatteryProfile.PROFILE_NAME,
                null, HostBatteryProfile.ATTRIBUTE_ON_BATTERY_CHANGE);
        for (int i = 0; i < events.size(); i++) {
            Event event = events.get(i);
            Intent mIntent = EventManager.createEventMessage(event);

            HostBatteryProfile.setAttribute(mIntent, HostBatteryProfile.ATTRIBUTE_ON_BATTERY_CHANGE);
            Bundle battery = new Bundle();
            HostBatteryProfile.setLevel(battery, mHostBatteryManager.getBatteryLevel());
            getContext().sendBroadcast(mIntent);
        }

        return START_STICKY;
    } else if (Intent.ACTION_POWER_CONNECTED.equals(action)
            || Intent.ACTION_POWER_DISCONNECTED.equals(action)) {
        // ????

        mHostBatteryManager.setBatteryRequest(intent);

        List<Event> events = EventManager.INSTANCE.getEventList(mDeviceId, HostBatteryProfile.PROFILE_NAME,
                null, HostBatteryProfile.ATTRIBUTE_ON_CHARGING_CHANGE);

        for (int i = 0; i < events.size(); i++) {
            Event event = events.get(i);
            Intent mIntent = EventManager.createEventMessage(event);

            HostBatteryProfile.setAttribute(mIntent, HostBatteryProfile.ATTRIBUTE_ON_CHARGING_CHANGE);
            Bundle charging = new Bundle();

            if (Intent.ACTION_POWER_CONNECTED.equals(action)) {
                HostBatteryProfile.setCharging(charging, true);
            } else {
                HostBatteryProfile.setCharging(charging, false);
            }

            HostBatteryProfile.setBattery(mIntent, charging);
            getContext().sendBroadcast(mIntent);
        }

        return START_STICKY;
    } else if (action.equals("android.intent.action.NEW_OUTGOING_CALL")) {
        // Phone

        List<Event> events = EventManager.INSTANCE.getEventList(mDeviceId, HostPhoneProfile.PROFILE_NAME, null,
                HostPhoneProfile.ATTRIBUTE_ON_CONNECT);

        for (int i = 0; i < events.size(); i++) {
            Event event = events.get(i);
            Intent mIntent = EventManager.createEventMessage(event);

            HostPhoneProfile.setAttribute(mIntent, HostPhoneProfile.ATTRIBUTE_ON_CONNECT);
            Bundle phoneStatus = new Bundle();
            HostPhoneProfile.setPhoneNumber(phoneStatus, intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER));
            HostPhoneProfile.setState(phoneStatus, CallState.START);
            HostPhoneProfile.setPhoneStatus(mIntent, phoneStatus);
            getContext().sendBroadcast(mIntent);
        }

        return START_STICKY;
    } else if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(action)
            || WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(action)) {
        // Wifi

        List<Event> events = EventManager.INSTANCE.getEventList(mDeviceId, HostConnectProfile.PROFILE_NAME,
                null, HostConnectProfile.ATTRIBUTE_ON_WIFI_CHANGE);

        for (int i = 0; i < events.size(); i++) {
            Event event = events.get(i);
            Intent mIntent = EventManager.createEventMessage(event);

            HostConnectProfile.setAttribute(mIntent, HostConnectProfile.ATTRIBUTE_ON_WIFI_CHANGE);
            Bundle wifiConnecting = new Bundle();
            WifiManager wifiMgr = (WifiManager) getContext().getSystemService(Context.WIFI_SERVICE);
            HostConnectProfile.setEnable(wifiConnecting, wifiMgr.isWifiEnabled());
            HostConnectProfile.setConnectStatus(mIntent, wifiConnecting);
            getContext().sendBroadcast(mIntent);
        }

        return START_STICKY;

    } else if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) {

        List<Event> events = EventManager.INSTANCE.getEventList(mDeviceId, HostConnectProfile.PROFILE_NAME,
                null, HostConnectProfile.ATTRIBUTE_ON_BLUETOOTH_CHANGE);

        for (int i = 0; i < events.size(); i++) {
            Event event = events.get(i);
            Intent mIntent = EventManager.createEventMessage(event);

            HostConnectProfile.setAttribute(mIntent, HostConnectProfile.ATTRIBUTE_ON_BLUETOOTH_CHANGE);
            Bundle bluetoothConnecting = new Bundle();
            BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
            HostConnectProfile.setEnable(bluetoothConnecting, mBluetoothAdapter.isEnabled());
            HostConnectProfile.setConnectStatus(mIntent, bluetoothConnecting);
            getContext().sendBroadcast(mIntent);
        }

        return START_STICKY;
    }
    return super.onStartCommand(intent, flags, startId);
}

From source file:org.proninyaroslav.libretorrent.services.TorrentTaskService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (intent != null) {
        ArrayList<String> ids = intent.getStringArrayListExtra(TorrentTaskServiceIPC.TAG_TORRENT_IDS_LIST);

        if (ids != null) {
            List<Torrent> torrents = new ArrayList<>();

            for (String id : ids) {
                torrents.add(repo.getTorrentByID(id));
            }/*from  ww w  . j a  va 2  s .  c  o  m*/

            addTorrents(torrents);
        }
    }

    if (isAlreadyRunning) {
        if (intent != null && intent.getAction() != null) {
            switch (intent.getAction()) {
            case NotificationReceiver.NOTIFY_ACTION_SHUTDOWN_APP:
                ipc.sendTerminateAllClients(clientCallbacks);
                clientCallbacks.clear();
                stopForeground(true);
                stopSelf(startId);
                break;
            case Intent.ACTION_BATTERY_LOW:
                if (pref.getBoolean(getString(R.string.pref_key_battery_control), false)) {
                    pauseTorrents.set(true);
                    pauseAll();
                }
                break;
            case Intent.ACTION_BATTERY_OKAY:
                if (pref.getBoolean(getString(R.string.pref_key_battery_control), false)
                        && !pref.getBoolean(getString(R.string.pref_key_download_and_upload_only_when_charging),
                                false)) {
                    pauseTorrents.set(false);
                    resumeAll();
                }
                break;
            case Intent.ACTION_POWER_CONNECTED:
                if (pref.getBoolean(getString(R.string.pref_key_download_and_upload_only_when_charging),
                        false)) {
                    pauseTorrents.set(false);
                    resumeAll();
                }
                break;
            case Intent.ACTION_POWER_DISCONNECTED:
                if (pref.getBoolean(getString(R.string.pref_key_download_and_upload_only_when_charging),
                        false)) {
                    pauseTorrents.set(true);
                    pauseAll();
                }
                break;
            }
        }

        return START_STICKY;
    }

    /* The first start */
    isAlreadyRunning = true;

    makeForegroundNotify();
    startUpdateForegroundNotify();

    return START_STICKY;
}

From source file:org.mariotaku.twidere.service.RefreshService.java

@Override
public void onCreate() {
    super.onCreate();
    GeneralComponentHelper.build(this).inject(this);
    mAlarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
    mPendingRefreshHomeTimelineIntent = PendingIntent.getBroadcast(this, 0,
            new Intent(BROADCAST_REFRESH_HOME_TIMELINE), 0);
    mPendingRefreshMentionsIntent = PendingIntent.getBroadcast(this, 0,
            new Intent(BROADCAST_REFRESH_NOTIFICATIONS), 0);
    mPendingRefreshDirectMessagesIntent = PendingIntent.getBroadcast(this, 0,
            new Intent(BROADCAST_REFRESH_DIRECT_MESSAGES), 0);
    mPendingRefreshTrendsIntent = PendingIntent.getBroadcast(this, 0, new Intent(BROADCAST_REFRESH_TRENDS), 0);
    final IntentFilter refreshFilter = new IntentFilter(BROADCAST_NOTIFICATION_DELETED);
    refreshFilter.addAction(BROADCAST_REFRESH_HOME_TIMELINE);
    refreshFilter.addAction(BROADCAST_REFRESH_NOTIFICATIONS);
    refreshFilter.addAction(BROADCAST_REFRESH_DIRECT_MESSAGES);
    refreshFilter.addAction(BROADCAST_RESCHEDULE_HOME_TIMELINE_REFRESHING);
    refreshFilter.addAction(BROADCAST_RESCHEDULE_MENTIONS_REFRESHING);
    refreshFilter.addAction(BROADCAST_RESCHEDULE_DIRECT_MESSAGES_REFRESHING);
    registerReceiver(mStateReceiver, refreshFilter);
    final IntentFilter batteryFilter = new IntentFilter();
    batteryFilter.addAction(Intent.ACTION_BATTERY_CHANGED);
    batteryFilter.addAction(Intent.ACTION_BATTERY_OKAY);
    batteryFilter.addAction(Intent.ACTION_BATTERY_LOW);
    batteryFilter.addAction(Intent.ACTION_POWER_CONNECTED);
    batteryFilter.addAction(Intent.ACTION_POWER_DISCONNECTED);
    final IntentFilter screenFilter = new IntentFilter();
    screenFilter.addAction(Intent.ACTION_SCREEN_ON);
    screenFilter.addAction(Intent.ACTION_SCREEN_OFF);
    screenFilter.addAction(Intent.ACTION_USER_PRESENT);
    registerReceiver(mPowerStateReceiver, batteryFilter);
    registerReceiver(mScreenStateReceiver, screenFilter);
    PowerStateReceiver.setServiceReceiverStarted(true);
    if (Utils.hasAutoRefreshAccounts(this)) {
        startAutoRefresh();//w  ww. ja va2 s. co  m
    } else {
        stopSelf();
    }
}

From source file:com.thomasokken.free42.Free42Activity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    instance = this;

    int init_mode;
    IntHolder version = new IntHolder();
    try {//  w  w  w.j  ava2  s.co  m
        stateFileInputStream = openFileInput("state");
    } catch (FileNotFoundException e) {
        stateFileInputStream = null;
    }
    if (stateFileInputStream != null) {
        if (read_shell_state(version))
            init_mode = 1;
        else {
            init_shell_state(-1);
            init_mode = 2;
        }
    } else {
        init_shell_state(-1);
        init_mode = 0;
    }
    setAlwaysRepaintFullDisplay(alwaysRepaintFullDisplay);
    if (alwaysOn)
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    if (style == 1)
        setTheme(android.R.style.Theme_NoTitleBar_Fullscreen);
    else if (style == 2) {
        try {
            Method m = View.class.getMethod("setSystemUiVisibility", int.class);
            m.invoke(getWindow().getDecorView(), PreferencesDialog.immersiveModeFlags);
        } catch (Exception e) {
        }
    }

    Configuration conf = getResources().getConfiguration();
    orientation = conf.orientation == Configuration.ORIENTATION_LANDSCAPE ? 1 : 0;

    mainHandler = new Handler();
    calcView = new CalcView(this);
    setContentView(calcView);
    printView = new PrintView(this);
    printScrollView = new ScrollView(this);
    printScrollView.setBackgroundColor(PRINT_BACKGROUND_COLOR);
    printScrollView.addView(printView);

    skin = null;
    if (skinName[orientation].length() == 0 && externalSkinName[orientation].length() > 0) {
        try {
            skin = new SkinLayout(externalSkinName[orientation], skinSmoothing[orientation],
                    displaySmoothing[orientation]);
        } catch (IllegalArgumentException e) {
        }
    }
    if (skin == null) {
        try {
            skin = new SkinLayout(skinName[orientation], skinSmoothing[orientation],
                    displaySmoothing[orientation]);
        } catch (IllegalArgumentException e) {
        }
    }
    if (skin == null) {
        try {
            skin = new SkinLayout(builtinSkinNames[0], skinSmoothing[orientation],
                    displaySmoothing[orientation]);
        } catch (IllegalArgumentException e) {
            // This one should never fail; we're loading a built-in skin.
        }
    }

    nativeInit();
    core_init(init_mode, version.value);
    if (stateFileInputStream != null) {
        try {
            stateFileInputStream.close();
        } catch (IOException e) {
        }
        stateFileInputStream = null;
    }

    lowBatteryReceiver = new BroadcastReceiver() {
        public void onReceive(Context ctx, Intent intent) {
            low_battery = intent.getAction().equals(Intent.ACTION_BATTERY_LOW);
            Rect inval = skin.update_annunciators(-1, -1, -1, -1, low_battery ? 1 : 0, -1, -1);
            if (inval != null)
                calcView.postInvalidateScaled(inval.left, inval.top, inval.right, inval.bottom);
        }
    };
    IntentFilter iff = new IntentFilter();
    iff.addAction(Intent.ACTION_BATTERY_LOW);
    iff.addAction(Intent.ACTION_BATTERY_OKAY);
    registerReceiver(lowBatteryReceiver, iff);

    if (preferredOrientation != this.getRequestedOrientation())
        setRequestedOrientation(preferredOrientation);

    soundPool = new SoundPool(1, AudioManager.STREAM_SYSTEM, 0);
    int[] soundResourceIds = { R.raw.tone0, R.raw.tone1, R.raw.tone2, R.raw.tone3, R.raw.tone4, R.raw.tone5,
            R.raw.tone6, R.raw.tone7, R.raw.tone8, R.raw.tone9, R.raw.squeak, R.raw.click };
    soundIds = new int[soundResourceIds.length];
    for (int i = 0; i < soundResourceIds.length; i++)
        soundIds[i] = soundPool.load(this, soundResourceIds[i], 1);
}

From source file:com.dwdesign.tweetings.service.TweetingsService.java

@Override
public void onCreate() {
    super.onCreate();
    mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    mAsyncTaskManager = ((TweetingsApplication) getApplication()).getAsyncTaskManager();
    mPreferences = getSharedPreferences(SHARED_PREFERENCES_NAME, MODE_PRIVATE);
    mResolver = getContentResolver();//from  www . j a  v a 2 s  .  c  o m
    mPendingRefreshHomeTimelineIntent = PendingIntent.getBroadcast(this, 0,
            new Intent(BROADCAST_REFRESH_HOME_TIMELINE), 0);
    mPendingRefreshMentionsIntent = PendingIntent.getBroadcast(this, 0, new Intent(BROADCAST_REFRESH_MENTIONS),
            0);
    mPendingRefreshDirectMessagesIntent = PendingIntent.getBroadcast(this, 0,
            new Intent(BROADCAST_REFRESH_DIRECT_MESSAGES), 0);
    final IntentFilter filter = new IntentFilter(BROADCAST_REFRESHSTATE_CHANGED);
    filter.addAction(BROADCAST_NOTIFICATION_CLEARED);
    filter.addAction(BROADCAST_REFRESH_HOME_TIMELINE);
    filter.addAction(BROADCAST_REFRESH_MENTIONS);
    filter.addAction(BROADCAST_REFRESH_DIRECT_MESSAGES);
    filter.addAction(Intent.ACTION_BATTERY_LOW);
    filter.addAction(Intent.ACTION_BATTERY_OKAY);
    registerReceiver(mStateReceiver, filter);
    startAutoRefresh();
}