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.cnlms.wear.NotificationHelper.java
public static void raiseNotificationAndDetectDismiss(final Context context) { raiseNotification(context, defaultBuilder(context).setDeleteIntent(PendingIntent.getBroadcast(context, 0, new Intent(context, NotificationDismissedReceiver.class), 0))); }
From source file:io.coldstart.android.GCMIntentService.java
private void sendRateLimitNotification(String rateLimitCount) { if (null == rateLimitCount) rateLimitCount = "0"; Intent intent = new Intent(this, TrapListActivity.class); intent.putExtra("forceDownload", true); PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0); Intent broadcastDownload = new Intent(); broadcastDownload.setAction(BatchDownloadReceiver.BROADCAST_ACTION); PendingIntent pBroadcastDownload = PendingIntent.getBroadcast(this, 0, broadcastDownload, 0); Intent broadcastIgnore = new Intent(); broadcastIgnore.setAction(BatchIgnoreReceiver.BROADCAST_ACTION); PendingIntent pBroadcastIgnore = PendingIntent.getBroadcast(this, 0, broadcastIgnore, 0); Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Notification notification = null; if (Build.VERSION.SDK_INT >= 16) { notification = new Notification.InboxStyle(new Notification.Builder(this) .setContentTitle("Inbound Traps have been rate limited") .setContentText(//from www . j a va 2 s .c o m "\"The number of traps being relayed to your phone has breeched the rate limit.") .setSmallIcon(R.drawable.ic_stat_ratelimit).setVibrate(new long[] { 0, 100, 200, 300 }) .setAutoCancel(true).setSound(uri).setPriority(Notification.PRIORITY_HIGH) .setTicker("Inbound Traps have been rate limited") .addAction(R.drawable.ic_download_batch, "Get Batched Traps", pBroadcastDownload) .addAction(R.drawable.ic_ignore, "Ignore Batch", pBroadcastIgnore)) .setBigContentTitle("Inbound Traps have been rate limited") .setSummaryText("Launch ColdStart.io to Manage These Events") .addLine("The number of traps relayed to you has breeched the rate limit.") .addLine("The current number of items queued is " + rateLimitCount).addLine(" ") .addLine("Tap \"Get Batched Traps\" to download the cached traps") .addLine("Tap \"Ignore Batch\" to delete them from the server.") .build(); } else { notification = new Notification.Builder(this).setContentTitle("Inbound Traps have been rate limited") .setContentText( "The number of traps being relayed to your phone has breeched the rate limit. The current number of items queued is " + rateLimitCount + "\nTap \"Get Alerts\" to batch download the outstanding traps or tap \"Ignore\" to delete them from the server.") .setSmallIcon(R.drawable.ic_stat_ratelimit).setContentIntent(pIntent) .setVibrate(new long[] { 0, 100, 200, 300 }).setAutoCancel(true).setSound(uri).build(); } NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); notificationManager.notify(43524, notification); }
From source file:com.keylesspalace.tusky.util.NotificationHelper.java
private static NotificationCompat.Builder newNotification(Context context, Notification body, AccountEntity account, boolean summary) { Intent summaryResultIntent = new Intent(context, MainActivity.class); summaryResultIntent.putExtra(ACCOUNT_ID, account.getId()); TaskStackBuilder summaryStackBuilder = TaskStackBuilder.create(context); summaryStackBuilder.addParentStack(MainActivity.class); summaryStackBuilder.addNextIntent(summaryResultIntent); PendingIntent summaryResultPendingIntent = summaryStackBuilder.getPendingIntent(notificationId, PendingIntent.FLAG_UPDATE_CURRENT); // we have to switch account here Intent eventResultIntent = new Intent(context, MainActivity.class); eventResultIntent.putExtra(ACCOUNT_ID, account.getId()); TaskStackBuilder eventStackBuilder = TaskStackBuilder.create(context); eventStackBuilder.addParentStack(MainActivity.class); eventStackBuilder.addNextIntent(eventResultIntent); PendingIntent eventResultPendingIntent = eventStackBuilder.getPendingIntent((int) account.getId(), PendingIntent.FLAG_UPDATE_CURRENT); Intent deleteIntent = new Intent(context, NotificationClearBroadcastReceiver.class); deleteIntent.putExtra(ACCOUNT_ID, account.getId()); PendingIntent deletePendingIntent = PendingIntent.getBroadcast(context, summary ? (int) account.getId() : notificationId, deleteIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(context, getChannelId(account, body)) .setSmallIcon(R.drawable.ic_notify) .setContentIntent(summary ? summaryResultPendingIntent : eventResultPendingIntent) .setDeleteIntent(deletePendingIntent) .setColor(BuildConfig.DEBUG ? Color.parseColor("#19A341") : ContextCompat.getColor(context, R.color.primary)) .setGroup(account.getAccountId()).setAutoCancel(true).setDefaults(0); // So it doesn't ring twice, notify only in Target callback setupPreferences(account, builder);/* w ww . j av a2 s. co m*/ return builder; }
From source file:at.diamonddogs.util.CacheManager.java
private PendingIntent getAlarmIntent(Context context) { Intent intent = new Intent(context.getApplicationContext(), CacheAlarmReceiver.class); intent.setAction(ACTION_INTENT_SCHEDULE_CACHE); PendingIntent pi = PendingIntent.getBroadcast(context.getApplicationContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); return pi;// w w w .j a va 2 s. c o m }
From source file:com.android.deskclock.alarms.AlarmStateManager.java
/** * Used in L and later devices where "next alarm" is stored in the Alarm Manager. *///from w w w . ja v a2 s .co m @TargetApi(Build.VERSION_CODES.LOLLIPOP) private static void updateNextAlarmInAlarmManager(Context context, AlarmInstance nextAlarm) { // Sets a surrogate alarm with alarm manager that provides the AlarmClockInfo for the // alarm that is going to fire next. The operation is constructed such that it is ignored // by AlarmStateManager. AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); int flags = nextAlarm == null ? PendingIntent.FLAG_NO_CREATE : 0; PendingIntent operation = PendingIntent.getBroadcast(context, 0 /* requestCode */, AlarmStateManager.createIndicatorIntent(context), flags); if (nextAlarm != null) { long alarmTime = nextAlarm.getAlarmTime().getTimeInMillis(); // Create an intent that can be used to show or edit details of the next alarm. PendingIntent viewIntent = PendingIntent.getActivity(context, nextAlarm.hashCode(), AlarmNotifications.createViewAlarmIntent(context, nextAlarm), PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager.AlarmClockInfo info = new AlarmManager.AlarmClockInfo(alarmTime, viewIntent); alarmManager.setAlarmClock(info, operation); } else if (operation != null) { alarmManager.cancel(operation); } }
From source file:com.deepak.myclock.alarms.AlarmNotifications.java
public static void showAlarmNotification(Context context, AlarmInstance instance) { Log.v("Displaying alarm notification for alarm instance: " + instance.mId); NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); // Close dialogs and window shade, so this will display context.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)); Resources resources = context.getResources(); NotificationCompat.Builder notification = new NotificationCompat.Builder(context) .setContentTitle(instance.getLabelOrDefault(context)) .setContentText(AlarmUtils.getFormattedTime(context, instance.getAlarmTime())) .setSmallIcon(R.drawable.stat_notify_alarm).setOngoing(true).setAutoCancel(false).setWhen(0); // Setup Snooze Action Intent snoozeIntent = AlarmStateManager.createStateChangeIntent(context, "SNOOZE_TAG", instance, AlarmInstance.SNOOZE_STATE); PendingIntent snoozePendingIntent = PendingIntent.getBroadcast(context, instance.hashCode(), snoozeIntent, PendingIntent.FLAG_UPDATE_CURRENT); notification.addAction(R.drawable.stat_notify_alarm, resources.getString(R.string.alarm_alert_snooze_text), snoozePendingIntent);/* ww w. ja v a 2 s . c om*/ // Setup Dismiss Action Intent dismissIntent = AlarmStateManager.createStateChangeIntent(context, "DISMISS_TAG", instance, AlarmInstance.DISMISSED_STATE); PendingIntent dismissPendingIntent = PendingIntent.getBroadcast(context, instance.hashCode(), dismissIntent, PendingIntent.FLAG_UPDATE_CURRENT); notification.addAction(android.R.drawable.ic_menu_close_clear_cancel, resources.getString(R.string.alarm_alert_dismiss_text), dismissPendingIntent); // Setup Content Action Intent contentIntent = AlarmInstance.createIntent(context, AlarmActivity.class, instance.mId); notification.setContentIntent(PendingIntent.getActivity(context, instance.hashCode(), contentIntent, PendingIntent.FLAG_UPDATE_CURRENT)); // Setup fullscreen intent /*Intent fullScreenIntent = AlarmInstance.createIntent(context, AlarmActivity.class, instance.mId); // set action, so we can be different then content pending intent fullScreenIntent.setAction("fullscreen_activity"); fullScreenIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_USER_ACTION); notification.setFullScreenIntent(PendingIntent.getActivity(context, instance.hashCode(), fullScreenIntent, PendingIntent.FLAG_UPDATE_CURRENT), true);*/ notification.setPriority(NotificationCompat.PRIORITY_MAX); nm.cancel(instance.hashCode()); nm.notify(instance.hashCode(), notification.build()); }
From source file:com.ferdi2005.secondgram.MusicPlayerService.java
public void setListeners(RemoteViews view) { PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, new Intent(NOTIFY_PREVIOUS), PendingIntent.FLAG_UPDATE_CURRENT); view.setOnClickPendingIntent(R.id.player_previous, pendingIntent); pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, new Intent(NOTIFY_CLOSE), PendingIntent.FLAG_UPDATE_CURRENT); view.setOnClickPendingIntent(R.id.player_close, pendingIntent); pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, new Intent(NOTIFY_PAUSE), PendingIntent.FLAG_UPDATE_CURRENT); view.setOnClickPendingIntent(R.id.player_pause, pendingIntent); pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, new Intent(NOTIFY_NEXT), PendingIntent.FLAG_UPDATE_CURRENT); view.setOnClickPendingIntent(R.id.player_next, pendingIntent); pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, new Intent(NOTIFY_PLAY), PendingIntent.FLAG_UPDATE_CURRENT); view.setOnClickPendingIntent(R.id.player_play, pendingIntent); }
From source file:com.androidinspain.deskclock.alarms.AlarmStateManager.java
/** * Used in L and later devices where "next alarm" is stored in the Alarm Manager. *//*w w w . j ava2s. com*/ @TargetApi(Build.VERSION_CODES.LOLLIPOP) private static void updateNextAlarmInAlarmManager(Context context, AlarmInstance nextAlarm) { // Sets a surrogate alarm with alarm manager that provides the AlarmClockInfo for the // alarm that is going to fire next. The operation is constructed such that it is ignored // by AlarmStateManager. final AlarmManager alarmManager = (AlarmManager) context.getSystemService(ALARM_SERVICE); final int flags = nextAlarm == null ? PendingIntent.FLAG_NO_CREATE : 0; final PendingIntent operation = PendingIntent.getBroadcast(context, 0 /* requestCode */, AlarmStateManager.createIndicatorIntent(context), flags); if (nextAlarm != null) { LogUtils.i("Setting upcoming AlarmClockInfo for alarm: " + nextAlarm.mId); long alarmTime = nextAlarm.getAlarmTime().getTimeInMillis(); // Create an intent that can be used to show or edit details of the next alarm. PendingIntent viewIntent = PendingIntent.getActivity(context, nextAlarm.hashCode(), AlarmNotifications.createViewAlarmIntent(context, nextAlarm), PendingIntent.FLAG_UPDATE_CURRENT); final AlarmClockInfo info = new AlarmClockInfo(alarmTime, viewIntent); Utils.updateNextAlarm(alarmManager, info, operation); } else if (operation != null) { LogUtils.i("Canceling upcoming AlarmClockInfo"); alarmManager.cancel(operation); } }
From source file:com.hhunj.hhudata.SearchBookContentsActivity.java
private void sendSMS(String phoneNumber, String message) { // ---sends an SMS message to another device--- SmsManager sms = SmsManager.getDefault(); String SENT_SMS_ACTION = "SENT_SMS_ACTION"; String DELIVERED_SMS_ACTION = "DELIVERED_SMS_ACTION"; // create the sentIntent parameter Intent sentIntent = new Intent(SENT_SMS_ACTION); PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, sentIntent, 0); // create the deilverIntent parameter Intent deliverIntent = new Intent(DELIVERED_SMS_ACTION); PendingIntent deliverPI = PendingIntent.getBroadcast(this, 0, deliverIntent, 0); // register the Broadcast Receivers registerReceiver(new BroadcastReceiver() { @Override/*from ww w . j ava2 s . c o m*/ public void onReceive(Context _context, Intent _intent) { switch (getResultCode()) { case Activity.RESULT_OK: Toast.makeText(getBaseContext(), "SMS sent success actions", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_GENERIC_FAILURE: Toast.makeText(getBaseContext(), "SMS generic failure actions", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_RADIO_OFF: Toast.makeText(getBaseContext(), "SMS radio off failure actions", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_NULL_PDU: Toast.makeText(getBaseContext(), "SMS null PDU failure actions", Toast.LENGTH_SHORT).show(); break; } } }, new IntentFilter(SENT_SMS_ACTION)); registerReceiver(new BroadcastReceiver() { @Override public void onReceive(Context _context, Intent _intent) { Toast.makeText(getBaseContext(), "SMS delivered actions", Toast.LENGTH_SHORT).show(); } }, new IntentFilter(DELIVERED_SMS_ACTION)); // if message's length more than 70 , // then call divideMessage to dive message into several part ,and call // sendTextMessage() // else direct call sendTextMessage() if (message.length() > 70) { ArrayList<String> msgs = sms.divideMessage(message); for (String msg : msgs) { sms.sendTextMessage(phoneNumber, null, msg, sentPI, deliverPI); } } else { sms.sendTextMessage(phoneNumber, null, message, sentPI, deliverPI); } }
From source file:fr.bmartel.android.fadecandy.service.FadecandyService.java
/** * dispatched attached usb device to fadecandy server native interface. * * @param device Usb device to be dispatched. *//* w w w. j a v a 2s. c o m*/ private void dispatchAttached(UsbDevice device) { if (!mUsbManager.hasPermission(device)) { Log.v(TAG, "Requesting permissiom to device"); PendingIntent mPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0); mUsbManager.requestPermission(device, mPermissionIntent); } else { Log.v(TAG, "Already has permission : opening device"); UsbItem item = openDevice(device); int fd = item.getConnection().getFileDescriptor(); dispatchUsb(item, fd); } }