Search in sources :

Example 11 with AlarmManager

use of android.app.AlarmManager in project Signal-Android by WhisperSystems.

the class PersistentAlarmManagerListener method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    long scheduledTime = getNextScheduledExecutionTime(context);
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    Intent alarmIntent = new Intent(context, getClass());
    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, alarmIntent, 0);
    if (System.currentTimeMillis() >= scheduledTime) {
        scheduledTime = onAlarm(context, scheduledTime);
    }
    Log.w(TAG, getClass() + " scheduling for: " + scheduledTime);
    alarmManager.cancel(pendingIntent);
    alarmManager.set(AlarmManager.RTC_WAKEUP, scheduledTime, pendingIntent);
}
Also used : AlarmManager(android.app.AlarmManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Example 12 with AlarmManager

use of android.app.AlarmManager in project Signal-Android by WhisperSystems.

the class KeyCachingService method handleActivityStarted.

private void handleActivityStarted() {
    Log.w("KeyCachingService", "Incrementing activity count...");
    AlarmManager alarmManager = (AlarmManager) this.getSystemService(ALARM_SERVICE);
    alarmManager.cancel(pending);
    activitiesRunning++;
}
Also used : AlarmManager(android.app.AlarmManager)

Example 13 with AlarmManager

use of android.app.AlarmManager in project Talon-for-Twitter by klinker24.

the class ActivityFragment method onRefreshStarted.

@Override
public void onRefreshStarted() {
    new AsyncTask<Void, Void, Cursor>() {

        private boolean update = false;

        @Override
        protected void onPreExecute() {
            DrawerActivity.canSwitch = false;
        }

        @Override
        protected Cursor doInBackground(Void... params) {
            ActivityUtils utils = new ActivityUtils(getActivity());
            update = utils.refreshActivity();
            AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
            long now = new Date().getTime();
            long alarm = now + DrawerActivity.settings.activityRefresh;
            PendingIntent pendingIntent = PendingIntent.getService(context, ACTIVITY_REFRESH_ID, new Intent(context, ActivityRefreshService.class), 0);
            if (DrawerActivity.settings.activityRefresh != 0)
                am.setRepeating(AlarmManager.RTC_WAKEUP, alarm, DrawerActivity.settings.activityRefresh, pendingIntent);
            else
                am.cancel(pendingIntent);
            if (settings.syncSecondMentions) {
                context.startService(new Intent(context, SecondActivityRefreshService.class));
            }
            return ActivityDataSource.getInstance(context).getCursor(currentAccount);
        }

        @Override
        protected void onPostExecute(Cursor cursor) {
            Cursor c = null;
            try {
                c = cursorAdapter.getCursor();
            } catch (Exception e) {
            }
            cursorAdapter = setAdapter(cursor);
            try {
                listView.setAdapter(cursorAdapter);
            } catch (Exception e) {
            }
            if (cursor.getCount() == 0) {
                spinner.setVisibility(View.VISIBLE);
            } else {
                spinner.setVisibility(View.GONE);
            }
            try {
                if (update) {
                    showToastBar(getString(R.string.new_activity), getString(R.string.ok), 400, true, toTopListener);
                }
            } catch (Exception e) {
            // user closed the app before it was done
            }
            refreshLayout.setRefreshing(false);
            DrawerActivity.canSwitch = true;
            try {
                c.close();
            } catch (Exception e) {
            }
        }
    }.execute();
}
Also used : AlarmManager(android.app.AlarmManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) Cursor(android.database.Cursor) ActivityUtils(com.klinker.android.twitter.utils.ActivityUtils) Date(java.util.Date)

Example 14 with AlarmManager

use of android.app.AlarmManager in project Talon-for-Twitter by klinker24.

the class NewScheduledTweet method createAlarm.

public void createAlarm(int alarmId) {
    Intent serviceIntent = new Intent(getApplicationContext(), SendScheduledTweet.class);
    serviceIntent.putExtra(ViewScheduledTweets.EXTRA_TEXT, mEditText.getText().toString());
    serviceIntent.putExtra("account", settings.currentAccount);
    serviceIntent.putExtra("alarm_id", alarmId);
    PendingIntent pi = getDistinctPendingIntent(serviceIntent, alarmId);
    AlarmManager am = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
    am.set(AlarmManager.RTC_WAKEUP, setDate.getTime(), pi);
}
Also used : AlarmManager(android.app.AlarmManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Example 15 with AlarmManager

use of android.app.AlarmManager in project Talon-for-Twitter by klinker24.

the class ViewScheduledTweets method cancelAlarm.

public void cancelAlarm(int alarmId) {
    Intent serviceIntent = new Intent(getApplicationContext(), SendScheduledTweet.class);
    PendingIntent pi = getDistinctPendingIntent(serviceIntent, alarmId);
    AlarmManager am = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
    am.cancel(pi);
}
Also used : AlarmManager(android.app.AlarmManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Aggregations

AlarmManager (android.app.AlarmManager)471 PendingIntent (android.app.PendingIntent)349 Intent (android.content.Intent)323 Calendar (java.util.Calendar)75 SuppressLint (android.annotation.SuppressLint)24 Date (java.util.Date)24 Context (android.content.Context)22 SharedPreferences (android.content.SharedPreferences)20 SimpleDateFormat (java.text.SimpleDateFormat)18 Test (org.junit.Test)17 VisibleForTesting (com.android.internal.annotations.VisibleForTesting)13 Config (org.robolectric.annotation.Config)13 Handler (android.os.Handler)11 HashMap (java.util.HashMap)11 PowerManager (android.os.PowerManager)10 File (java.io.File)10 Map (java.util.Map)10 Activity (android.app.Activity)9 ShadowAlarmManager (org.robolectric.shadows.ShadowAlarmManager)9 TargetApi (android.annotation.TargetApi)8