Example usage for android.content Context ALARM_SERVICE

List of usage examples for android.content Context ALARM_SERVICE

Introduction

In this page you can find the example usage for android.content Context ALARM_SERVICE.

Prototype

String ALARM_SERVICE

To view the source code for android.content Context ALARM_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.app.AlarmManager for receiving intents at a time of your choosing.

Usage

From source file:org.gnucash.android.ui.transaction.TransactionFormFragment.java

/**
 * Collects information from the fragment views and uses it to create 
 * and save a transaction//from w  w  w  .java2s .c om
 */
private void saveNewTransaction() {
    Calendar cal = new GregorianCalendar(mDate.get(Calendar.YEAR), mDate.get(Calendar.MONTH),
            mDate.get(Calendar.DAY_OF_MONTH), mTime.get(Calendar.HOUR_OF_DAY), mTime.get(Calendar.MINUTE),
            mTime.get(Calendar.SECOND));
    String name = mNameEditText.getText().toString();
    String description = mDescriptionEditText.getText().toString();
    BigDecimal amountBigd = parseInputToDecimal(mAmountEditText.getText().toString());

    long accountID = ((TransactionsActivity) getSherlockActivity()).getCurrentAccountID();
    Currency currency = Currency.getInstance(mTransactionsDbAdapter.getCurrencyCode(accountID));
    Money amount = new Money(amountBigd, currency);
    TransactionType type;
    if (mAccountType.hasDebitNormalBalance()) {
        type = amount.isNegative() ? TransactionType.CREDIT : TransactionType.DEBIT;
    } else
        type = amount.isNegative() ? TransactionType.DEBIT : TransactionType.CREDIT;
    if (mTransaction != null) {
        mTransaction.setAmount(amount);
        mTransaction.setName(name);
        mTransaction.setTransactionType(type);
    } else {
        mTransaction = new Transaction(amount, name, type);
    }

    mTransaction.setAccountUID(mTransactionsDbAdapter.getAccountUID(accountID));
    mTransaction.setTime(cal.getTimeInMillis());
    mTransaction.setDescription(description);

    //set the double account
    if (mUseDoubleEntry) {
        long doubleAccountId = mDoubleAccountSpinner.getSelectedItemId();
        //negate the transaction before saving if we are in the double account
        if (isInDoubleAccount()) {
            mTransaction.setAmount(amount.negate());
            mTransaction.setAccountUID(mTransactionsDbAdapter.getAccountUID(doubleAccountId));
            mTransaction.setDoubleEntryAccountUID(mTransactionsDbAdapter.getAccountUID(accountID));
        } else {
            mTransaction.setAccountUID(mTransactionsDbAdapter.getAccountUID(accountID));
            mTransaction.setDoubleEntryAccountUID(mTransactionsDbAdapter.getAccountUID(doubleAccountId));
        }
    }
    //save the normal transaction first
    mTransactionsDbAdapter.addTransaction(mTransaction);

    //set up recurring transaction if requested
    int recurrenceIndex = mRecurringTransactionSpinner.getSelectedItemPosition();
    if (recurrenceIndex != 0) {
        String[] recurrenceOptions = getResources().getStringArray(R.array.recurrence_period_millis);
        long recurrencePeriodMillis = Long.parseLong(recurrenceOptions[recurrenceIndex]);
        long firstRunMillis = System.currentTimeMillis() + recurrencePeriodMillis;

        Transaction recurringTransaction = new Transaction(mTransaction, true);
        recurringTransaction.setRecurrencePeriod(recurrencePeriodMillis);
        long recurringTransactionId = mTransactionsDbAdapter.addTransaction(recurringTransaction);

        PendingIntent recurringPendingIntent = PendingIntent.getBroadcast(getActivity().getApplicationContext(),
                (int) recurringTransactionId, Transaction.createIntent(mTransaction),
                PendingIntent.FLAG_UPDATE_CURRENT);
        AlarmManager alarmManager = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE);
        alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, firstRunMillis, recurrencePeriodMillis,
                recurringPendingIntent);
    }

    //update widgets, if any
    WidgetConfigurationActivity.updateAllWidgets(getActivity().getApplicationContext());

    finish();
}

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 w w  w  .  j av 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();
}

From source file:org.sipdroid.sipua.ui.Receiver.java

public static void alarm(int renew_time, Class<?> cls) {
    if (!Sipdroid.release)
        Log.i("SipUA:", "alarm " + renew_time);
    Intent intent = new Intent(mContext, cls);
    PendingIntent sender = PendingIntent.getBroadcast(mContext, 0, intent, 0);
    AlarmManager am = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
    am.cancel(sender);//from   w  ww . j  a va 2s  . c  o  m
    if (renew_time > 0)
        am.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + renew_time * 1000, sender);
}

From source file:org.metawatch.manager.Monitors.java

static void startAlarmTicker(Context context) {
    if (Preferences.logging)
        Log.d(MetaWatch.TAG, "startAlarmTicker()");
    alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    intent = new Intent(context, AlarmReceiver.class);
    intent.putExtra("action_update", "update");
    sender = PendingIntent.getBroadcast(context, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, 0, AlarmManager.INTERVAL_HALF_HOUR, sender);
}

From source file:com.vuze.android.remote.service.VuzeService.java

@Override
public void onTaskRemoved(Intent rootIntent) {
    if (CorePrefs.DEBUG_CORE) {
        Log.d(TAG, "onTaskRemoved: ");
    }//from   www .  j  a va 2s  .  co  m

    AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent(getApplicationContext(), getClass());
    intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 1, intent, 0);
}

From source file:org.voidsink.anewjkuapp.utils.AppUtils.java

public static void updateSyncAlarm(Context context, boolean reCreateAlarm) {
    boolean mIsCalendarSyncEnabled = false;
    boolean mIsKusssSyncEnable = false;
    boolean mIsMasterSyncEnabled = ContentResolver.getMasterSyncAutomatically();

    if (mIsMasterSyncEnabled) {
        final Account mAccount = getAccount(context);
        if (mAccount != null) {
            mIsCalendarSyncEnabled = ContentResolver.getSyncAutomatically(mAccount,
                    CalendarContractWrapper.AUTHORITY());
            mIsKusssSyncEnable = ContentResolver.getSyncAutomatically(mAccount, KusssContentContract.AUTHORITY);
        }/*from  w  w w  .j  a v  a2 s  .co  m*/
    }

    Log.d(TAG, String.format("MasterSync=%b, CalendarSync=%b, KusssSync=%b", mIsMasterSyncEnabled,
            mIsCalendarSyncEnabled, mIsKusssSyncEnable));

    AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent(context, SyncAlarmService.class);
    intent.putExtra(Consts.ARG_UPDATE_CAL, !mIsCalendarSyncEnabled);
    intent.putExtra(Consts.ARG_UPDATE_KUSSS, !mIsKusssSyncEnable);
    intent.putExtra(Consts.ARG_RECREATE_SYNC_ALARM, true);
    intent.putExtra(Consts.SYNC_SHOW_PROGRESS, true);

    // check if pending intent exists
    reCreateAlarm = reCreateAlarm
            || (PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_NO_CREATE) == null);

    // new pending intent
    PendingIntent alarmIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    if (!mIsMasterSyncEnabled || !mIsCalendarSyncEnabled || !mIsKusssSyncEnable) {
        if (reCreateAlarm) {
            long interval = PreferenceWrapper.getSyncInterval(context) * DateUtils.HOUR_IN_MILLIS;

            // synchronize in half an hour
            am.setInexactRepeating(AlarmManager.RTC_WAKEUP,
                    System.currentTimeMillis() + AlarmManager.INTERVAL_HALF_HOUR, interval, alarmIntent);
        }
    } else {
        am.cancel(alarmIntent);
    }
}

From source file:com.android.mail.utils.NotificationActionUtils.java

/**
 * Registers a timeout for the undo notification such that when it expires, the undo bar will
 * disappear, and the action will be performed.
 *//*from   w  w w  .  jav a 2s  .  c o  m*/
public static void registerUndoTimeout(final Context context, final NotificationAction notificationAction) {
    LogUtils.i(LOG_TAG, "registerUndoTimeout for %s", notificationAction.getNotificationActionType());

    if (sUndoTimeoutMillis == -1) {
        sUndoTimeoutMillis = context.getResources().getInteger(R.integer.undo_notification_timeout);
    }

    final AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

    final long triggerAtMills = SystemClock.elapsedRealtime() + sUndoTimeoutMillis;

    final PendingIntent pendingIntent = createUndoTimeoutPendingIntent(context, notificationAction);

    alarmManager.set(AlarmManager.ELAPSED_REALTIME, triggerAtMills, pendingIntent);
}

From source file:org.kontalk.service.msgcenter.MessageCenterService.java

@Override
public void onCreate() {
    configure();/*  w w w. j a  va2s . c  om*/

    // create the roster store
    mRosterStore = new SQLiteRosterStore(this);

    // create the global wake lock
    PowerManager pwr = (PowerManager) getSystemService(Context.POWER_SERVICE);
    mWakeLock = pwr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, Kontalk.TAG);
    mWakeLock.setReferenceCounted(false);
    mPingLock = pwr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, Kontalk.TAG + "-Ping");
    mPingLock.setReferenceCounted(false);

    mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    // cancel any pending alarm intent
    cancelIdleAlarm();

    mLocalBroadcastManager = LocalBroadcastManager.getInstance(this);
    mPushService = PushServiceManager.getInstance(this);

    // create idle handler
    createIdleHandler();

    // create main thread handler
    mHandler = new Handler();

    // register screen off listener for manual inactivation
    registerInactivity();
}

From source file:co.taqat.call.assistant.AssistantActivity.java

public void restartApplication() {
    mPrefs.firstLaunchSuccessful();/* w  w w .j  a va2s  .c  o m*/

    Intent mStartActivity = new Intent(this, LinphoneLauncherActivity.class);
    PendingIntent mPendingIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(),
            mStartActivity, PendingIntent.FLAG_CANCEL_CURRENT);
    AlarmManager mgr = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
    mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 500, mPendingIntent);

    stopService(new Intent(Intent.ACTION_MAIN).setClass(this, LinphoneService.class));
    android.os.Process.killProcess(android.os.Process.myPid());
}

From source file:com.android.mail.utils.NotificationActionUtils.java

/**
 * Cancels the undo timeout for a notification action. This should be called if the undo
 * notification is clicked (to prevent the action from being performed anyway) or cleared (since
 * we have already performed the action).
 */// w  ww .ja v  a2 s.c  om
public static void cancelUndoTimeout(final Context context, final NotificationAction notificationAction) {
    LogUtils.i(LOG_TAG, "cancelUndoTimeout for %s", notificationAction.getNotificationActionType());

    final AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

    final PendingIntent pendingIntent = createUndoTimeoutPendingIntent(context, notificationAction);

    alarmManager.cancel(pendingIntent);
}