Example usage for android.content.pm PackageManager COMPONENT_ENABLED_STATE_ENABLED

List of usage examples for android.content.pm PackageManager COMPONENT_ENABLED_STATE_ENABLED

Introduction

In this page you can find the example usage for android.content.pm PackageManager COMPONENT_ENABLED_STATE_ENABLED.

Prototype

int COMPONENT_ENABLED_STATE_ENABLED

To view the source code for android.content.pm PackageManager COMPONENT_ENABLED_STATE_ENABLED.

Click Source Link

Document

Flag for #setApplicationEnabledSetting(String,int,int) and #setComponentEnabledSetting(ComponentName,int,int) : This component or application has been explictily enabled, regardless of what it has specified in its manifest.

Usage

From source file:com.farmerbb.taskbar.fragment.AdvancedFragment.java

@SuppressLint("SetTextI18n")
@Override/*w ww .j  av  a2 s.  co m*/
public boolean onPreferenceClick(final Preference p) {
    final SharedPreferences pref = U.getSharedPreferences(getActivity());

    switch (p.getKey()) {
    case "clear_pinned_apps":
        Intent clearIntent = null;

        switch (pref.getString("theme", "light")) {
        case "light":
            clearIntent = new Intent(getActivity(), ClearDataActivity.class);
            break;
        case "dark":
            clearIntent = new Intent(getActivity(), ClearDataActivityDark.class);
            break;
        }

        startActivity(clearIntent);
        break;
    case "launcher":
        if (U.canDrawOverlays(getActivity())) {
            ComponentName component = new ComponentName(getActivity(), HomeActivity.class);
            getActivity().getPackageManager().setComponentEnabledSetting(component,
                    ((CheckBoxPreference) p).isChecked() ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
                            : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                    PackageManager.DONT_KILL_APP);
        } else {
            U.showPermissionDialog(getActivity());
            ((CheckBoxPreference) p).setChecked(false);
        }

        if (!((CheckBoxPreference) p).isChecked())
            LocalBroadcastManager.getInstance(getActivity())
                    .sendBroadcast(new Intent("com.farmerbb.taskbar.KILL_HOME_ACTIVITY"));
        break;
    case "keyboard_shortcut":
        ComponentName component = new ComponentName(getActivity(), KeyboardShortcutActivity.class);
        getActivity().getPackageManager()
                .setComponentEnabledSetting(component,
                        ((CheckBoxPreference) p).isChecked() ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
                                : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                        PackageManager.DONT_KILL_APP);
        break;
    case "dashboard_grid_size":
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        LinearLayout dialogLayout = (LinearLayout) View.inflate(getActivity(), R.layout.dashboard_size_dialog,
                null);

        boolean isPortrait = getActivity().getApplicationContext().getResources()
                .getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;
        boolean isLandscape = getActivity().getApplicationContext().getResources()
                .getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;

        int editTextId = -1;
        int editText2Id = -1;

        if (isPortrait) {
            editTextId = R.id.fragmentEditText2;
            editText2Id = R.id.fragmentEditText1;
        }

        if (isLandscape) {
            editTextId = R.id.fragmentEditText1;
            editText2Id = R.id.fragmentEditText2;
        }

        final EditText editText = (EditText) dialogLayout.findViewById(editTextId);
        final EditText editText2 = (EditText) dialogLayout.findViewById(editText2Id);

        builder.setView(dialogLayout).setTitle(R.string.dashboard_grid_size)
                .setPositiveButton(R.string.action_ok, (dialog, id) -> {
                    boolean successfullyUpdated = false;

                    String widthString = editText.getText().toString();
                    String heightString = editText2.getText().toString();

                    if (widthString.length() > 0 && heightString.length() > 0) {
                        int width = Integer.parseInt(widthString);
                        int height = Integer.parseInt(heightString);

                        if (width > 0 && height > 0) {
                            SharedPreferences.Editor editor = pref.edit();
                            editor.putInt("dashboard_width", width);
                            editor.putInt("dashboard_height", height);
                            editor.apply();

                            updateDashboardGridSize(true);
                            successfullyUpdated = true;
                        }
                    }

                    if (!successfullyUpdated)
                        U.showToast(getActivity(), R.string.invalid_grid_size);
                }).setNegativeButton(R.string.action_cancel, null);

        editText.setText(Integer.toString(pref.getInt("dashboard_width",
                getActivity().getApplicationContext().getResources().getInteger(R.integer.dashboard_width))));
        editText2.setText(Integer.toString(pref.getInt("dashboard_height",
                getActivity().getApplicationContext().getResources().getInteger(R.integer.dashboard_height))));

        AlertDialog dialog = builder.create();
        dialog.show();

        new Handler().post(() -> {
            InputMethodManager imm = (InputMethodManager) getActivity()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.showSoftInput(editText2, InputMethodManager.SHOW_IMPLICIT);
        });

        break;
    case "navigation_bar_buttons":
        Intent intent = null;

        switch (pref.getString("theme", "light")) {
        case "light":
            intent = new Intent(getActivity(), NavigationBarButtonsActivity.class);
            break;
        case "dark":
            intent = new Intent(getActivity(), NavigationBarButtonsActivityDark.class);
            break;
        }

        startActivity(intent);
        break;
    }

    return true;
}

From source file:com.appsaur.tarucassist.AlarmReceiver.java

public void setAlarm(Context context, Calendar calendar, int ID) {
    mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

    // Put Reminder ID in Intent Extra
    Intent intent = new Intent(context, AlarmReceiver.class);
    intent.putExtra(BaseActivity.EXTRA_REMINDER_ID, Integer.toString(ID));
    mPendingIntent = PendingIntent.getBroadcast(context, ID, intent, PendingIntent.FLAG_CANCEL_CURRENT);

    // Calculate notification time
    Calendar c = Calendar.getInstance();
    long currentTime = c.getTimeInMillis();
    long diffTime = calendar.getTimeInMillis() - currentTime;

    // Start alarm using notification time
    mAlarmManager.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + diffTime, mPendingIntent);

    // Restart alarm if device is rebooted
    ComponentName receiver = new ComponentName(context, BootReceiver.class);
    PackageManager pm = context.getPackageManager();
    pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
            PackageManager.DONT_KILL_APP);
}

From source file:cn.studyjams.s2.sj0119.NForget.AlarmReceiver.java

public void setRepeatAlarm(Context context, Calendar calendar, int ID, long RepeatTime) {
    mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

    // Put Reminder ID in Intent Extra
    Intent intent = new Intent(context, AlarmReceiver.class);
    intent.putExtra(ReminderEditActivity.EXTRA_REMINDER_ID, Integer.toString(ID));
    mPendingIntent = PendingIntent.getBroadcast(context, ID, intent, PendingIntent.FLAG_CANCEL_CURRENT);

    // Calculate notification timein
    Calendar c = Calendar.getInstance();
    long currentTime = c.getTimeInMillis();
    long diffTime = calendar.getTimeInMillis() - currentTime;

    // Start alarm using initial notification time and repeat interval time
    mAlarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + diffTime,
            RepeatTime, mPendingIntent);

    // Restart alarm if device is rebooted
    ComponentName receiver = new ComponentName(context, BootReceiver.class);
    PackageManager pm = context.getPackageManager();
    pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
            PackageManager.DONT_KILL_APP);
}

From source file:com.appsaur.tarucassist.AutomuteAlarmReceiver.java

public void setRepeatAlarm(Context context, Calendar calendar, int ID, long RepeatTime) {
    mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

    // Put Reminder ID in Intent Extra
    Intent intent = new Intent(context, AutomuteAlarmReceiver.class);
    intent.putExtra(BaseActivity.EXTRA_REMINDER_ID, Integer.toString(ID));
    mPendingIntent = PendingIntent.getBroadcast(context, ID, intent, PendingIntent.FLAG_CANCEL_CURRENT);

    // Calculate notification timein
    Calendar c = Calendar.getInstance();
    long currentTime = c.getTimeInMillis();
    long diffTime = calendar.getTimeInMillis() - currentTime;

    // Start alarm using initial notification time and repeat interval time
    mAlarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + diffTime,
            RepeatTime, mPendingIntent);

    // Restart alarm if device is rebooted
    ComponentName receiver = new ComponentName(context, BootReceiver.class);
    PackageManager pm = context.getPackageManager();
    pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
            PackageManager.DONT_KILL_APP);
}

From source file:co.carlosandresjimenez.android.gotit.notification.AlarmReceiver.java

/**
 * Sets a repeating alarm that runs once a day at approximately 8:30 a.m. When the
 * alarm fires, the app broadcasts an Intent to this WakefulBroadcastReceiver.
 *
 * @param context/*from   w w w  .  j av a2  s  .co  m*/
 */
public void setAlarm(Context context) {

    // If the alarm has been set, cancel it.
    if (alarmMgr != null) {
        alarmIntent.cancel();
        alarmMgr.cancel(alarmIntent);
    }

    alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent(context, AlarmReceiver.class);
    alarmIntent = PendingIntent.getBroadcast(context, 0, intent, 0);

    int userFrequencySetting = Utility.getNotificationFrequency(context);

    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());
    calendar.add(Calendar.HOUR, userFrequencySetting);

    // Set the alarm to fire in X hours according to the device's
    // clock and user settings, and to repeat according to user settings
    alarmMgr.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
            userFrequencySetting * ONE_HOUR_MILLISECONDS, alarmIntent);

    ComponentName receiver = new ComponentName(context, BootReceiver.class);
    PackageManager pm = context.getPackageManager();

    pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
            PackageManager.DONT_KILL_APP);
}

From source file:com.concentricsky.android.khanacademy.data.remote.LibraryUpdaterTask.java

@Override
protected Integer doInBackground(Void... params) {

    SharedPreferences prefs = dataService.getSharedPreferences(SETTINGS_NAME, Context.MODE_PRIVATE);

    // Connectivity receiver.
    final NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo();
    ComponentName receiver = new ComponentName(dataService, WifiReceiver.class);
    PackageManager pm = dataService.getPackageManager();
    if (activeNetwork == null || !activeNetwork.isConnected()) {
        // We've missed a scheduled update. Enable the receiver so it can launch an update when we reconnect.
        Log.d(LOG_TAG, "Missed library update: not connected. Enabling connectivity receiver.");
        pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
                PackageManager.DONT_KILL_APP);
        return RESULT_CODE_FAILURE;
    } else {//from  www. jav  a 2s.c  o  m
        // We are connected. Disable the receiver.
        Log.d(LOG_TAG, "Library updater connected. Disabling connectivity receiver.");
        pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                PackageManager.DONT_KILL_APP);
    }

    InputStream in = null;
    String etag = prefs.getString(SETTING_LIBRARY_ETAG, null);

    try {
        HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
        if (etag != null && !force) {
            conn.setRequestProperty("If-None-Match", etag);
        }

        int code = conn.getResponseCode();
        switch (code) {
        case HttpStatus.SC_NOT_MODIFIED:
            // If we got a 304, we're done.
            // Use failure code to indicate there is no temp db to copy over.
            Log.d(LOG_TAG, "304 in library response.");
            return RESULT_CODE_FAILURE;
        default:
            // Odd, but on 1/3/13 I received correct json responses with a -1 for responseCode. Fall through.
            Log.w(LOG_TAG, "Error code in library response: " + code);
        case HttpStatus.SC_OK:
            // Parse response.
            in = conn.getInputStream();
            JsonFactory factory = new JsonFactory();
            final JsonParser parser = factory.createJsonParser(in);

            SQLiteDatabase tempDb = tempDbHelper.getWritableDatabase();
            tempDb.beginTransaction();
            try {
                tempDb.execSQL("delete from topic");
                tempDb.execSQL("delete from topicvideo");
                tempDb.execSQL("delete from video");

                parseObject(parser, tempDb, null, 0);
                tempDb.setTransactionSuccessful();
            } catch (Exception e) {
                e.printStackTrace();
                return RESULT_CODE_FAILURE;
            } finally {
                tempDb.endTransaction();
                tempDb.close();
            }

            // Save etag once we've successfully parsed the response.
            etag = conn.getHeaderField("ETag");
            prefs.edit().putString(SETTING_LIBRARY_ETAG, etag).apply();

            // Move this new content from the temp db into the main one.
            mergeDbs();

            return RESULT_CODE_SUCCESS;
        }
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (JsonParseException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        tempDbHelper.close();
    }

    return RESULT_CODE_FAILURE;
}

From source file:com.github.michalbednarski.intentslab.StartActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem interceptionOption = menu.findItem(R.id.interception);
    interceptionOption.setChecked(getPackageManager().getComponentEnabledSetting(
            mInterceptActivityComponentName) == PackageManager.COMPONENT_ENABLED_STATE_ENABLED);
    Utils.updateLegacyCheckedIcon(interceptionOption);
    return true;/*from  www. j  a  v  a 2s .c om*/
}

From source file:de.j4velin.wifiAutoOff.Preferences.java

@SuppressLint("NewApi")
@Override/*w w  w  .  j a v a 2s  .c o m*/
public boolean onCreateOptionsMenu(final Menu menu) {
    getMenuInflater().inflate(R.menu.menu, menu);
    if (android.os.Build.VERSION.SDK_INT >= 11) {
        CompoundButton enable = (CompoundButton) menu.findItem(R.id.enable).getActionView();
        if (android.os.Build.VERSION.SDK_INT < 14) {
            enable.setText("Enable");
        }
        enable.setChecked(getPackageManager().getComponentEnabledSetting(
                new ComponentName(this, Receiver.class)) != PackageManager.COMPONENT_ENABLED_STATE_DISABLED);
        // disable initially if not checked
        if (!enable.isChecked()) {
            @SuppressWarnings("deprecation")
            PreferenceScreen ps = getPreferenceScreen();
            for (int i = 0; i < ps.getPreferenceCount(); i++) {
                ps.getPreference(i).setEnabled(false);
            }
        }
        enable.setOnCheckedChangeListener(new OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                @SuppressWarnings("deprecation")
                PreferenceScreen ps = getPreferenceScreen();
                // start at 1 to skip "status" preference
                for (int i = 1; i < ps.getPreferenceCount(); i++) {
                    ps.getPreference(i).setEnabled(isChecked);
                }
                getPackageManager().setComponentEnabledSetting(
                        new ComponentName(Preferences.this, Receiver.class),
                        isChecked ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
                                : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                        PackageManager.DONT_KILL_APP);
                if (!isChecked)
                    stopService(new Intent(Preferences.this, ScreenChangeDetector.class));
                getPackageManager().setComponentEnabledSetting(
                        new ComponentName(Preferences.this, ScreenChangeDetector.class),
                        isChecked ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
                                : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                        PackageManager.DONT_KILL_APP);
            }
        });
    }
    return true;
}

From source file:com.android.transmart.services.PlaceCheckinService.java

/**
 * {@inheritDoc}//from   w  ww  . jav  a 2  s. c  o  m
 * Perform a checkin the specified venue. If the checkin fails, add it to the queue and
 * set an alarm to retry.
 * 
 * Query the checkin queue to see if there are pending checkins to be retried.
 */
@Override
protected void onHandleIntent(Intent intent) {
    // Retrieve the details for the checkin to perform.
    String reference = intent.getStringExtra(LocationConstants.EXTRA_KEY_REFERENCE);
    String id = intent.getStringExtra(LocationConstants.EXTRA_KEY_ID);
    long timeStamp = intent.getLongExtra(LocationConstants.EXTRA_KEY_TIME_STAMP, 0);

    // Check if we're running in the foreground, if not, check if
    // we have permission to do background updates.
    boolean backgroundAllowed = cm.getBackgroundDataSetting();
    boolean inBackground = sharedPreferences.getBoolean(LocationConstants.EXTRA_KEY_IN_BACKGROUND, true);

    if (reference != null && !backgroundAllowed && inBackground) {
        addToQueue(timeStamp, reference, id);
        return;
    }

    // Check to see if we are connected to a data network.
    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting();

    // If we're not connected then disable the retry Alarm, enable the Connectivity Changed Receiver
    // and add the new checkin directly to the queue. The Connectivity Changed Receiver will listen
    // for when we connect to a network and start this service to retry the checkins.
    if (!isConnected) {
        // No connection so no point triggering an alarm to retry until we're connected.
        alarmManager.cancel(retryQueuedCheckinsPendingIntent);

        // Enable the Connectivity Changed Receiver to listen for connection to a network
        // so we can commit the pending checkins.
        PackageManager pm = getPackageManager();
        ComponentName connectivityReceiver = new ComponentName(this, ConnectivityChangedReceiver.class);
        pm.setComponentEnabledSetting(connectivityReceiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
                PackageManager.DONT_KILL_APP);

        // Add this checkin to the queue.
        addToQueue(timeStamp, reference, id);
    } else {
        // Execute the checkin. If it fails, add it to the retry queue.
        if (reference != null) {
            if (!checkin(timeStamp, reference, id))
                addToQueue(timeStamp, reference, id);
        }

        // Retry the queued checkins.
        ArrayList<String> successfulCheckins = new ArrayList<String>();
        Cursor queuedCheckins = contentResolver.query(QueuedCheckinsContentProvider.CONTENT_URI, null, null,
                null, null);
        try {
            // Retry each checkin.
            while (queuedCheckins.moveToNext()) {
                long queuedTimeStamp = queuedCheckins
                        .getLong(queuedCheckins.getColumnIndex(QueuedCheckinsContentProvider.KEY_TIME_STAMP));
                String queuedReference = queuedCheckins
                        .getString(queuedCheckins.getColumnIndex(QueuedCheckinsContentProvider.KEY_REFERENCE));
                String queuedId = queuedCheckins
                        .getString(queuedCheckins.getColumnIndex(QueuedCheckinsContentProvider.KEY_ID));
                if (queuedReference == null || checkin(queuedTimeStamp, queuedReference, queuedId))
                    successfulCheckins.add(queuedReference);
            }

            // Delete the queued checkins that were successful.
            if (successfulCheckins.size() > 0) {
                StringBuilder sb = new StringBuilder("(" + QueuedCheckinsContentProvider.KEY_REFERENCE + "='"
                        + successfulCheckins.get(0) + "'");
                for (int i = 1; i < successfulCheckins.size(); i++)
                    sb.append(" OR " + QueuedCheckinsContentProvider.KEY_REFERENCE + " = '"
                            + successfulCheckins.get(i) + "'");
                sb.append(")");
                int deleteCount = contentResolver.delete(QueuedCheckinsContentProvider.CONTENT_URI,
                        sb.toString(), null);
                Log.d(TAG, "Deleted: " + deleteCount);
            }

            // If there are still queued checkins then set a non-waking alarm to retry them.
            queuedCheckins.requery();
            if (queuedCheckins.getCount() > 0) {
                long triggerAtTime = System.currentTimeMillis() + LocationConstants.CHECKIN_RETRY_INTERVAL;
                alarmManager.set(AlarmManager.ELAPSED_REALTIME, triggerAtTime,
                        retryQueuedCheckinsPendingIntent);
            } else
                alarmManager.cancel(retryQueuedCheckinsPendingIntent);
        } finally {
            queuedCheckins.close();
        }
    }
}

From source file:com.radioactiveyak.location_best_practices.services.PlaceCheckinService.java

/**
 * {@inheritDoc}/*w  w w .jav a2  s .co m*/
 * Perform a checkin the specified venue. If the checkin fails, add it to the queue and
 * set an alarm to retry.
 * 
 * Query the checkin queue to see if there are pending checkins to be retried.
 */
@Override
protected void onHandleIntent(Intent intent) {
    // Retrieve the details for the checkin to perform.
    String reference = intent.getStringExtra(PlacesConstants.EXTRA_KEY_REFERENCE);
    String id = intent.getStringExtra(PlacesConstants.EXTRA_KEY_ID);
    long timeStamp = intent.getLongExtra(PlacesConstants.EXTRA_KEY_TIME_STAMP, 0);

    // Check if we're running in the foreground, if not, check if
    // we have permission to do background updates.
    boolean backgroundAllowed = cm.getBackgroundDataSetting();
    boolean inBackground = sharedPreferences.getBoolean(PlacesConstants.EXTRA_KEY_IN_BACKGROUND, true);

    if (reference != null && !backgroundAllowed && inBackground) {
        addToQueue(timeStamp, reference, id);
        return;
    }

    // Check to see if we are connected to a data network.
    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting();

    // If we're not connected then disable the retry Alarm, enable the Connectivity Changed Receiver
    // and add the new checkin directly to the queue. The Connectivity Changed Receiver will listen
    // for when we connect to a network and start this service to retry the checkins.
    if (!isConnected) {
        // No connection so no point triggering an alarm to retry until we're connected.
        alarmManager.cancel(retryQueuedCheckinsPendingIntent);

        // Enable the Connectivity Changed Receiver to listen for connection to a network
        // so we can commit the pending checkins.
        PackageManager pm = getPackageManager();
        ComponentName connectivityReceiver = new ComponentName(this, ConnectivityChangedReceiver.class);
        pm.setComponentEnabledSetting(connectivityReceiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
                PackageManager.DONT_KILL_APP);

        // Add this checkin to the queue.
        addToQueue(timeStamp, reference, id);
    } else {
        // Execute the checkin. If it fails, add it to the retry queue.
        if (reference != null) {
            if (!checkin(timeStamp, reference, id))
                addToQueue(timeStamp, reference, id);
        }

        // Retry the queued checkins.
        ArrayList<String> successfulCheckins = new ArrayList<String>();
        Cursor queuedCheckins = contentResolver.query(QueuedCheckinsContentProvider.CONTENT_URI, null, null,
                null, null);
        try {
            // Retry each checkin.
            while (queuedCheckins.moveToNext()) {
                long queuedTimeStamp = queuedCheckins
                        .getLong(queuedCheckins.getColumnIndex(QueuedCheckinsContentProvider.KEY_TIME_STAMP));
                String queuedReference = queuedCheckins
                        .getString(queuedCheckins.getColumnIndex(QueuedCheckinsContentProvider.KEY_REFERENCE));
                String queuedId = queuedCheckins
                        .getString(queuedCheckins.getColumnIndex(QueuedCheckinsContentProvider.KEY_ID));
                if (queuedReference == null || checkin(queuedTimeStamp, queuedReference, queuedId))
                    successfulCheckins.add(queuedReference);
            }

            // Delete the queued checkins that were successful.
            if (successfulCheckins.size() > 0) {
                StringBuilder sb = new StringBuilder("(" + QueuedCheckinsContentProvider.KEY_REFERENCE + "='"
                        + successfulCheckins.get(0) + "'");
                for (int i = 1; i < successfulCheckins.size(); i++)
                    sb.append(" OR " + QueuedCheckinsContentProvider.KEY_REFERENCE + " = '"
                            + successfulCheckins.get(i) + "'");
                sb.append(")");
                int deleteCount = contentResolver.delete(QueuedCheckinsContentProvider.CONTENT_URI,
                        sb.toString(), null);
                Log.d(TAG, "Deleted: " + deleteCount);
            }

            // If there are still queued checkins then set a non-waking alarm to retry them.
            queuedCheckins.requery();
            if (queuedCheckins.getCount() > 0) {
                long triggerAtTime = System.currentTimeMillis() + PlacesConstants.CHECKIN_RETRY_INTERVAL;
                alarmManager.set(AlarmManager.ELAPSED_REALTIME, triggerAtTime,
                        retryQueuedCheckinsPendingIntent);
            } else
                alarmManager.cancel(retryQueuedCheckinsPendingIntent);
        } finally {
            queuedCheckins.close();
        }
    }
}