List of usage examples for android.app AlarmManager ELAPSED_REALTIME
int ELAPSED_REALTIME
To view the source code for android.app AlarmManager ELAPSED_REALTIME.
Click Source Link
From source file:me.tatarka.support.internal.job.JobStore.java
private void markForBootSession(JobStatus jobStatus) { // Pending intents are cleared on reboot. Therefore, we can use one to mark that we haven't // rebooted yet. Intent intent = new Intent(mContext, JobSchedulerService.class).setAction(jobStatus.toShortString()); PendingIntent pendingIntent = PendingIntent.getService(mContext, jobStatus.getJobId(), intent, PendingIntent.FLAG_CANCEL_CURRENT); // Have the alarm manager hold on to our pending intent so it will still be there even if our app is killed. AlarmManager am = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE); am.set(AlarmManager.ELAPSED_REALTIME, Long.MAX_VALUE, pendingIntent); }
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 ww w . ja v a 2 s .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:indrora.atomic.irc.IRCService.java
/** * Connect to the given server//from ww w . j a v a2 s . c om */ public void connect(final Server server) { final int serverId = server.getId(); final int reconnectInterval = settings.getReconnectInterval() * 60000; final IRCService service = this; if (settings.isReconnectEnabled()) { server.setMayReconnect(true); } new Thread("Connect thread for " + server.getTitle()) { @Override public void run() { synchronized (alarmIntentsLock) { if (alarmIntents == null) return; alarmIntents.remove(serverId); ReconnectReceiver lastReceiver = alarmReceivers.remove(serverId); if (lastReceiver != null) { unregisterReceiver(lastReceiver); } } if (settings.isReconnectEnabled() && !server.mayReconnect()) { return; } try { IRCConnection connection = getConnection(serverId); connection.setNickname(server.getIdentity().getNickname()); connection.setAliases(server.getIdentity().getAliases()); connection.setIdent(server.getIdentity().getIdent()); connection.setRealName(server.getIdentity().getRealName()); connection.setUseSSL(server.useSSL()); X509TrustManager[] trustMgr = MemorizingTrustManager.getInstanceList(getApplicationContext()); connection.setTrustManagers(trustMgr); if (server.getCharset() != null) { connection.setEncoding(server.getCharset()); } if (server.getAuthentication().hasSaslCredentials()) { connection.setSaslCredentials(server.getAuthentication().getSaslUsername(), server.getAuthentication().getSaslPassword()); } if (server.getPassword() != "") { connection.connect(server.getHost(), server.getPort(), server.getPassword()); } else { connection.connect(server.getHost(), server.getPort()); } } catch (Exception e) { server.setStatus(Status.DISCONNECTED); NetworkInfo ninf = ((ConnectivityManager) (IRCService.this .getSystemService(Service.CONNECTIVITY_SERVICE))).getActiveNetworkInfo(); if (ninf == null) { _isTransient = false; } else { _isTransient = !(ninf.getState() == NetworkInfo.State.CONNECTED); } Intent sIntent = Broadcast.createServerIntent(Broadcast.SERVER_UPDATE, serverId); sendBroadcast(sIntent); IRCConnection connection = getConnection(serverId); Message message; if (e instanceof NickAlreadyInUseException) { message = new Message(getString(R.string.nickname_in_use, connection.getNick())); server.setMayReconnect(false); } else if (e instanceof IrcException) { message = new Message( getString(R.string.irc_login_error, server.getHost(), server.getPort())); server.setMayReconnect(false); } else if (e instanceof SSLException) { // This happens when we declined the SSL certificate most of the time // We should check what really happened. message = new Message("SSL negotiation failed: " + e.toString()); } else { message = new Message( getString(R.string.could_not_connect, server.getHost(), server.getPort()) + ":\n" + e.getMessage()); if (settings.isReconnectEnabled()) { Intent rIntent = new Intent(Broadcast.SERVER_RECONNECT + serverId); PendingIntent pendingRIntent = PendingIntent.getBroadcast(service, 0, rIntent, 0); AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); ReconnectReceiver receiver = new ReconnectReceiver(service, server); synchronized (alarmIntentsLock) { alarmReceivers.put(serverId, receiver); registerReceiver(receiver, new IntentFilter(Broadcast.SERVER_RECONNECT + serverId)); am.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + reconnectInterval, pendingRIntent); alarmIntents.put(serverId, pendingRIntent); } } } message.setColor(Message.MessageColor.ERROR); message.setIcon(R.drawable.error); server.getConversation(ServerInfo.DEFAULT_NAME).addMessage(message); Intent cIntent = Broadcast.createConversationIntent(Broadcast.CONVERSATION_MESSAGE, serverId, ServerInfo.DEFAULT_NAME); sendBroadcast(cIntent); } } }.start(); }
From source file:com.mikecorrigan.bohrium.pubsub.RegistrationClient.java
private void c2dmHandleRegistrationResponse(final Context context, Intent intent) { Log.d(TAG, "c2dmHandleRegistrationResponse: context=" + context + ", intent=" + intent + ", extras=" + Utils.bundleToString(intent.getExtras())); final String registrationId = intent.getStringExtra(EXTRA_REGISTRATION_ID); String error = intent.getStringExtra(EXTRA_ERROR); String unregistered = intent.getStringExtra(EXTRA_UNREGISTERED); Log.d(TAG, "handleRegistration: registrationId = " + registrationId + ", error = " + error + ", unregistered = " + unregistered); mConfiguration.putLong(LAST_CHANGE, System.currentTimeMillis()); if (unregistered != null) { // Unregistered mConfiguration.putString(REG_ID, ""); setStateAndNotify(REGISTRATION_STATE_UNREGISTERING, REGISTRATION_SUBSTATE_NONE); mHandler.sendEmptyMessage(EVENT_UNREGISTER_COMPLETE); } else if (error != null) { // Registration failed. Log.e(TAG, "Registration error " + error); mConfiguration.putString(REG_ID, ""); setStateAndNotify(REGISTRATION_STATE_ERROR, error); if ("SERVICE_NOT_AVAILABLE".equals(error)) { long backoffTime = mConfiguration.getLong(C2DM_BACKOFF, DEFAULT_BACKOFF); // For this error, try again later. Log.d(TAG, "Scheduling registration retry, backoff = " + backoffTime); Intent retryIntent = new Intent(C2DM_INTENT_RETRY); PendingIntent retryPIntent = PendingIntent.getBroadcast(context, 0 /* requestCode */, retryIntent, 0 /* flags */); AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); am.set(AlarmManager.ELAPSED_REALTIME, backoffTime, retryPIntent); // Next retry should wait longer. backoffTime *= BACKOFF_MULTIPLIER; if (backoffTime > MAX_BACKOFF) { backoffTime = MAX_BACKOFF; mConfiguration.putLong(C2DM_BACKOFF, backoffTime); }//from w w w . ja v a 2 s. c om // Save the backoff time. writePreferences(); } } else { mConfiguration.putString(REG_ID, registrationId); setStateAndNotify(REGISTRATION_STATE_REGISTERING, REGISTRATION_SUBSTATE_HAVE_REG_ID); mHandler.sendEmptyMessage(EVENT_REGISTER_COMPLETE); } }