List of usage examples for android.app PendingIntent getBroadcast
public static PendingIntent getBroadcast(Context context, int requestCode, Intent intent, @Flags int flags)
From source file:com.conferenceengineer.android.iosched.gcm.command.SyncCommand.java
private void scheduleSync(Context context, int syncJitter) { int jitterMillis = (int) (RANDOM.nextFloat() * syncJitter); final String debugMessage = "Scheduling next sync for " + jitterMillis + "ms"; LOGI(TAG, debugMessage);/*from w w w .j a v a 2s . c o m*/ ((AlarmManager) context.getSystemService(Context.ALARM_SERVICE)).set(AlarmManager.RTC, System.currentTimeMillis() + jitterMillis, PendingIntent.getBroadcast(context, 0, new Intent(context, TriggerSyncReceiver.class), PendingIntent.FLAG_CANCEL_CURRENT)); }
From source file:com.oliversride.wordryo.UpdateCheckReceiver.java
public static void restartTimer(Context context) { AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(context, UpdateCheckReceiver.class); PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, 0); am.cancel(pi);/*w w w.j av a 2s.com*/ long interval_millis = INTERVAL_ONEDAY; if (!devOK(context)) { interval_millis *= INTERVAL_NDAYS; } interval_millis = (interval_millis / 2) + Math.abs(Utils.nextRandomInt() % interval_millis); am.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + interval_millis, interval_millis, pi); }
From source file:com.cryart.sabbathschool.util.SSNotification.java
public static void cancelRepeatingNotification(Context context) { AlarmManager _SSAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent _SSUpdateServiceIntent = new Intent(context, SSBroadcastReceiver.class); PendingIntent _SSPendingUpdateServiceIntent = PendingIntent.getBroadcast(context, 0, _SSUpdateServiceIntent, 0);/* w ww . j av a 2 s .co m*/ try { _SSAlarmManager.cancel(_SSPendingUpdateServiceIntent); } catch (Exception e) { } }
From source file:com.keylesspalace.tusky.util.NotificationMaker.java
public static void make(final Context context, final int notifyId, Notification body) { final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); final SharedPreferences notificationPreferences = context.getSharedPreferences("Notifications", Context.MODE_PRIVATE); if (!filterNotification(preferences, body)) { return;//from w w w .j a v a 2s . com } String rawCurrentNotifications = notificationPreferences.getString("current", "[]"); JSONArray currentNotifications; try { currentNotifications = new JSONArray(rawCurrentNotifications); } catch (JSONException e) { currentNotifications = new JSONArray(); } boolean alreadyContains = false; for (int i = 0; i < currentNotifications.length(); i++) { try { if (currentNotifications.getString(i).equals(body.account.getDisplayName())) { alreadyContains = true; } } catch (JSONException e) { e.printStackTrace(); } } if (!alreadyContains) { currentNotifications.put(body.account.getDisplayName()); } notificationPreferences.edit().putString("current", currentNotifications.toString()).commit(); Intent resultIntent = new Intent(context, MainActivity.class); resultIntent.putExtra("tab_position", 1); TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); Intent deleteIntent = new Intent(context, NotificationClearBroadcastReceiver.class); PendingIntent deletePendingIntent = PendingIntent.getBroadcast(context, 0, deleteIntent, PendingIntent.FLAG_CANCEL_CURRENT); final NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_notify).setContentIntent(resultPendingIntent) .setDeleteIntent(deletePendingIntent).setDefaults(0); // So it doesn't ring twice, notify only in Target callback if (currentNotifications.length() == 1) { builder.setContentTitle(titleForType(context, body)) .setContentText(truncateWithEllipses(bodyForType(body), 40)); Target mTarget = new Target() { @Override public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) { builder.setLargeIcon(bitmap); setupPreferences(preferences, builder); ((NotificationManager) (context.getSystemService(Context.NOTIFICATION_SERVICE))) .notify(notifyId, builder.build()); } @Override public void onBitmapFailed(Drawable errorDrawable) { } @Override public void onPrepareLoad(Drawable placeHolderDrawable) { } }; Picasso.with(context).load(body.account.avatar).placeholder(R.drawable.avatar_default) .transform(new RoundedTransformation(7, 0)).into(mTarget); } else { setupPreferences(preferences, builder); try { builder.setContentTitle(String.format(context.getString(R.string.notification_title_summary), currentNotifications.length())) .setContentText(truncateWithEllipses(joinNames(context, currentNotifications), 40)); } catch (JSONException e) { e.printStackTrace(); } } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { builder.setVisibility(android.app.Notification.VISIBILITY_PRIVATE); builder.setCategory(android.app.Notification.CATEGORY_SOCIAL); } ((NotificationManager) (context.getSystemService(Context.NOTIFICATION_SERVICE))).notify(notifyId, builder.build()); }
From source file:cl.chihau.holaauto.MessagingService.java
private void sendNotificationForConversation(int conversationId, String sender, String message, long timestamp) { // A pending Intent for reads PendingIntent readPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), conversationId, getMessageReadIntent(conversationId), PendingIntent.FLAG_UPDATE_CURRENT); /// Add the code to create the UnreadConversation // Build a RemoteInput for receiving voice input in a Car Notification RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY).build(); // Building a Pending Intent for the reply action to trigger PendingIntent replyIntent = PendingIntent.getBroadcast(getApplicationContext(), conversationId, getMessageReplyIntent(conversationId), PendingIntent.FLAG_UPDATE_CURRENT); // Create the UnreadConversation and populate it with the participant name, // read and reply intents. NotificationCompat.CarExtender.UnreadConversation.Builder unreadConversationBuilder = new NotificationCompat.CarExtender.UnreadConversation.Builder( sender).setLatestTimestamp(timestamp).setReadPendingIntent(readPendingIntent) .setReplyAction(replyIntent, remoteInput); // Note: Add messages from oldest to newest to the UnreadConversation.Builder // Since we are sending a single message here we simply add the message. // In a real world application there could be multiple messages which should be ordered // and added from oldest to newest. unreadConversationBuilder.addMessage(message); /// End create UnreadConversation NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext()) .setSmallIcon(R.drawable.notification_icon) .setLargeIcon(BitmapFactory.decodeResource(getApplicationContext().getResources(), R.drawable.android_contact)) .setContentText(message).setWhen(timestamp).setContentTitle(sender) .setContentIntent(readPendingIntent).setContentIntent(readPendingIntent) /// Extend the notification with CarExtender. .extend(new NotificationCompat.CarExtender() .setUnreadConversation(unreadConversationBuilder.build())) /// End/*from w w w .ja v a 2 s. c o m*/ ; Log.d(TAG, "Sending notification " + conversationId + " conversation: " + message); NotificationManagerCompat.from(this).notify(conversationId, builder.build()); }
From source file:com.example.pyrkesa.shwc.Device.java
public NotificationCompat.Action getAction(Context c) { ACTION_DEMAND += (this.id + cmd.cmd + cmd.value); Intent demandIntent = new Intent(c, ActionReceiver.class) .putExtra(EXTRA_CMD, this.getJSONObject().toString()).setAction(ACTION_DEMAND); PendingIntent demandPendingIntent = PendingIntent.getBroadcast(c, 0, demandIntent, 0); NotificationCompat.Action Action = null; if (type == 1) { if (cmd.value.equalsIgnoreCase("0")) { Action = new NotificationCompat.Action.Builder(R.drawable.eteindre, this.name, demandPendingIntent) .build();/*from w w w . j a v a 2s. c o m*/ } else { Action = new NotificationCompat.Action.Builder(R.drawable.allumer, this.name, demandPendingIntent) .build(); } } else { Action = new NotificationCompat.Action.Builder(R.drawable.go_to_phone_00157, "problme", demandPendingIntent).build(); } if (Action != null) { return Action; } else { Action = new NotificationCompat.Action.Builder(R.drawable.ic_full_cancel, "problme", demandPendingIntent).build(); return Action; } }
From source file:com.google.android.apps.dashclock.PeriodicExtensionRefreshReceiver.java
/** * Cancels the refresh schedule if one isn't set already. *//*ww w .j av a 2 s.c o m*/ protected static void cancelPeriodicRefresh(final Context context) { final AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); PendingIntent pi = PendingIntent.getBroadcast(context, 0, new Intent(context, PeriodicExtensionRefreshReceiver.class).setAction(ACTION_PERIODIC_ALARM), PendingIntent.FLAG_CANCEL_CURRENT); am.cancel(pi); }
From source file:br.ajmarques.cordova.plugin.localnotification.LocalNotification.java
/** * Set an alarm./*from ww w .j av a 2 s . co m*/ * * @param options * The options that can be specified per alarm. */ public static void add(Options options) { long triggerTime = options.getDate(); Intent intent = new Intent(context, Receiver.class).setAction("" + options.getId()) .putExtra(Receiver.OPTIONS, options.getJSONObject().toString()); AlarmManager am = getAlarmManager(); PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); am.set(AlarmManager.RTC_WAKEUP, triggerTime, pi); }
From source file:com.ayogo.cordova.notification.ScheduledNotificationManager.java
public ScheduledNotification scheduleNotification(String title, JSONObject options) { LOG.v(NotificationPlugin.TAG, "scheduleNotification: " + title); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); ScheduledNotification notification = new ScheduledNotification(title, options); long alarmTime = notification.at; if (alarmTime != 0) { //0 = uninitialized. saveNotification(notification);/*from w w w . j a v a2 s. c o m*/ LOG.v(NotificationPlugin.TAG, "create Intent: " + notification.tag); Intent intent = new Intent(context, TriggerReceiver.class); intent.setAction(notification.tag); PendingIntent pi = PendingIntent.getBroadcast(context, INTENT_REQUEST_CODE, intent, PendingIntent.FLAG_CANCEL_CURRENT); LOG.v(NotificationPlugin.TAG, "schedule alarm for: " + alarmTime); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { alarmManager.setExact(AlarmManager.RTC_WAKEUP, alarmTime, pi); } else { alarmManager.set(AlarmManager.RTC_WAKEUP, alarmTime, pi); } } else { // No "at", trigger the notification right now. showNotification(notification); } return notification; }
From source file:com.adstrosoftware.gpsplayground.activityrecognizer.ActivityRecognizerFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); client = new ActivityRecognitionClient(getActivity(), this, this); updateIntent = PendingIntent.getBroadcast(getActivity(), 0, new Intent(ACTION_ACTIVITY_UPDATE), PendingIntent.FLAG_UPDATE_CURRENT); activityUpdateBroadcastReceiver = new ActivityUpdateBroadcastReceiver(); }