Refine search
@Override protected void onHandleIntent(Intent intent) { mTodoText = intent.getStringExtra(TODOTEXT); mTodoUUID = (UUID) intent.getSerializableExtra(TODOUUID); Intent i = new Intent(this, ReminderActivity.class); i.putExtra(TodoNotificationService.TODOUUID, mTodoUUID); Intent deleteIntent = new Intent(this, DeleteNotificationService.class); deleteIntent.putExtra(TODOUUID, mTodoUUID); Notification notification = new Notification.Builder(this) .setContentTitle(mTodoText) .setSmallIcon(R.drawable.ic_done_white_24dp) .setAutoCancel(true) .setDefaults(Notification.DEFAULT_SOUND) .setDeleteIntent(PendingIntent.getService(this, mTodoUUID.hashCode(), deleteIntent, PendingIntent.FLAG_UPDATE_CURRENT)) .setContentIntent(PendingIntent.getActivity(this, mTodoUUID.hashCode(), i, PendingIntent.FLAG_UPDATE_CURRENT)) .build(); manager.notify(100, notification);
private Notification buildNotification() { Intent notifyIntent = new Intent(this, TermuxActivity.class); if (wakeLockHeld) contentText += " (wake lock held)"; Notification.Builder builder = new Notification.Builder(this); builder.setContentTitle(getText(R.string.application_name)); builder.setContentText(contentText); builder.setSmallIcon(R.drawable.ic_service_notification); builder.setContentIntent(pendingIntent); builder.setOngoing(true); builder.setPriority((wakeLockHeld) ? Notification.PRIORITY_HIGH : Notification.PRIORITY_LOW); builder.setShowWhen(false); builder.setColor(0xFF000000); builder.setChannelId(NOTIFICATION_CHANNEL_ID); Intent exitIntent = new Intent(this, TermuxService.class).setAction(ACTION_STOP_SERVICE); builder.addAction(android.R.drawable.ic_delete, res.getString(R.string.notification_action_exit), PendingIntent.getService(this, 0, exitIntent, 0)); R.string.notification_action_wake_lock); int actionIcon = wakeLockHeld ? android.R.drawable.ic_lock_idle_lock : android.R.drawable.ic_lock_lock; builder.addAction(actionIcon, actionTitle, PendingIntent.getService(this, 0, toggleWakeLockIntent, 0)); return builder.build();
Notification.Builder builder = new Notification.Builder(context) .setSmallIcon(R.drawable.block_canary_notification) .setWhen(System.currentTimeMillis()) .setContentTitle(contentTitle) .setContentText(contentText) .setAutoCancel(true) .setContentIntent(pendingIntent) .setDefaults(Notification.DEFAULT_SOUND); if (SDK_INT < JELLY_BEAN) { notification = builder.getNotification(); } else { notification = builder.build(); notificationManager.notify(0xDEAFBEEF, notification);
// prepare intent which is triggered if the // notification is selected Intent intent = new Intent(this, NotificationReceiver.class); PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0); // build notification // the addAction re-use the same intent to keep the example short Notification n = new Notification.Builder(this) .setContentTitle("New mail from " + "test@gmail.com") .setContentText("Subject") .setSmallIcon(R.drawable.icon) .setContentIntent(pIntent) .setAutoCancel(true) .addAction(R.drawable.icon, "Call", pIntent) .addAction(R.drawable.icon, "More", pIntent) .addAction(R.drawable.icon, "And more", pIntent).build(); NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); notificationManager.notify(0, n);
Intent intent = new Intent(this, MyBroadcastReceiver.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(), 0, intent, 0); Builder builder = new Notification.Builder(this): ..... code for your notification builder.setDeleteIntent(pendingIntent);
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) private void tryNewMiuiBadge(Context context, int badgeCount) throws ShortcutBadgeException { if (resolveInfo == null) { Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_HOME); resolveInfo = context.getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY); } if (resolveInfo != null) { NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Notification.Builder builder = new Notification.Builder(context) .setContentTitle("") .setContentText("") .setSmallIcon(resolveInfo.getIconResource()); Notification notification = builder.build(); try { Field field = notification.getClass().getDeclaredField("extraNotification"); Object extraNotification = field.get(notification); Method method = extraNotification.getClass().getDeclaredMethod("setMessageCount", int.class); method.invoke(extraNotification, badgeCount); mNotificationManager.notify(0, notification); } catch (Exception e) { throw new ShortcutBadgeException("not able to set badge", e); } } }
Notification.Builder mBuilder = new Notification.Builder(this) .setSmallIcon(R.drawable.cmplayer) .setContentTitle("CoderoMusicPlayer") .setContentText("PLayer0!"); Intent resultIntent = new Intent(this, AndroidBuildingMusicPlayerActivity.class); resultIntent.setAction(Intent.ACTION_MAIN); resultIntent.addCategory(Intent.CATEGORY_LAUNCHER); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, resultIntent, 0); mBuilder.setContentIntent(pendingIntent); NotificationManager mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); mNotificationManager.notify(1, mBuilder.build());
public class MyNewIntentService extends IntentService { private static final int NOTIFICATION_ID = 3; public MyNewIntentService() { super("MyNewIntentService"); } @Override protected void onHandleIntent(Intent intent) { Notification.Builder builder = new Notification.Builder(this); builder.setContentTitle("My Titel"); builder.setContentText("This is the Body"); builder.setSmallIcon(R.drawable.whatever); Intent notifyIntent = new Intent(this, MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(this, 2, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT); //to be able to launch your activity from the notification builder.setContentIntent(pendingIntent); Notification notificationCompat = builder.build(); NotificationManagerCompat managerCompat = NotificationManagerCompat.from(this); managerCompat.notify(NOTIFICATION_ID, notificationCompat); } }
public void onClick(View arg0) { Intent intent = new Intent("com.rj.notitfications.SECACTIVITY"); Notification.Builder builder = new Notification.Builder(MainActivity.this); builder.setAutoCancel(false); builder.setTicker("this is ticker text"); builder.setContentTitle("WhatsApp Notification"); builder.setContentText("You have a new message"); builder.setSmallIcon(R.drawable.ic_launcher); builder.setContentIntent(pendingIntent); builder.setOngoing(true); builder.setSubText("This is subtext..."); //API level 16 builder.setNumber(100); builder.build(); myNotication = builder.getNotification(); manager.notify(11, myNotication); manager.cancel(11);
private void sendNotification(String contentText) { Intent notificationIntent = new Intent(getApplicationContext(), MainActivity.class); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, 0); Notification n = new Notification.Builder(this) .setSmallIcon(R.drawable.ic_stat_kd) .setContentTitle("Possible Karma attack detected!") .setContentText(contentText) .setSound(defaultNotificationUri) .setLights(Color.RED, 500, 500) .setOnlyAlertOnce(true) .setContentIntent(intent) .setAutoCancel(true).build(); notificationManager.notify(0, n); }
Notification.Builder builder = new Notification.Builder(this); builder.setContentTitle(getString(R.string.title)) Intent shutdownActionIntent = new Intent(this, MyService.class); shutdownActionIntent.setAction(SHUTDOWN_NOTIFICATION_ACTION); PendingIntent.FLAG_UPDATE_CURRENT); builder.addAction(android.R.drawable.ic_lock_power_off, getString(R.string.shutdown_action), shutdownPendingIntent); builder.setPriority(Notification.PRIORITY_MAX); return builder.build(); } else { return builder.getNotification();
final Notification noti = new Notification.Builder(this) case 1: action = new Intent(ACTION_TOGGLE_PLAYBACK); action.setComponent(serviceName); pendingIntent = PendingIntent.getService(this, 1, action, 0); return pendingIntent; case 2: action = new Intent(ACTION_NEXT); action.setComponent(serviceName); pendingIntent = PendingIntent.getService(this, 2, action, 0);
Notification.Builder builder = new Notification.Builder(ctx); @SuppressWarnings("deprecation") Notification notification=builder.getNotification(); notification.when=when; notification.tickerText=tickerText; notification.flags |= Notification.FLAG_ONGOING_EVENT; CharSequence contentTitle = "From Shortcuts"; mNotificationManager.notify(548853, notification); radio.putExtra("DO", "radio"); PendingIntent pRadio = PendingIntent.getActivity(ctx, 0, radio, 0); view.setOnClickPendingIntent(R.id.radio, pRadio); volume.putExtra("DO", "volume"); PendingIntent pVolume = PendingIntent.getActivity(ctx, 1, volume, 0); view.setOnClickPendingIntent(R.id.volume, pVolume); reboot.putExtra("DO", "reboot"); PendingIntent pReboot = PendingIntent.getActivity(ctx, 5, reboot, 0); view.setOnClickPendingIntent(R.id.reboot, pReboot);
@Override protected void onHandleIntent(Intent intent) { if (intent != null) { int badgeCount = intent.getIntExtra("badgeCount", 0); mNotificationManager.cancel(notificationId); notificationId++; Notification.Builder builder = new Notification.Builder(getApplicationContext()) .setContentTitle("") .setContentText("") .setSmallIcon(R.drawable.ic_launcher); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { setupNotificationChannel(); builder.setChannelId(NOTIFICATION_CHANNEL); } Notification notification = builder.build(); ShortcutBadger.applyNotification(getApplicationContext(), notification, badgeCount); mNotificationManager.notify(notificationId, notification); } }
Notification foregroundNote; RemoteViews bigView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.notification_layout_big); // bigView.setOnClickPendingIntent() etc.. Notification.Builder mNotifyBuilder = new Notification.Builder(this); foregroundNote = mNotifyBuilder.setContentTitle("some string") .setContentText("Slide down on note to expand") .setSmallIcon(R.drawable.ic_stat_notify_white) .setLargeIcon(bigIcon) .build(); foregroundNote.bigContentView = bigView; // now show notification.. NotificationManager mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mNotifyManager.notify(1, foregroundNote);
Notification.Builder builder = new Notification.Builder(context) .setContentTitle(context.getString(R.string.leak_canary_notification_dumping)); Notification notification = LeakCanaryInternals.buildNotification(context, builder); NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); int notificationId = (int) SystemClock.uptimeMillis(); notificationManager.notify(notificationId, notification); Debug.dumpHprofData(heapDumpFile.getAbsolutePath()); cancelToast(toast); notificationManager.cancel(notificationId); return heapDumpFile; } catch (Exception e) {
new Notification.Builder(context) .setContentTitle(title) .setContentText(message) .setSmallIcon(smallIconResID) .setVibrate(new long[]{0, 250, 100, 250}) .setSound(soundUri) .setNumber(number) .setContentIntent(pendingIntent) .setTicker(title + ": " + message) .setPriority(Notification.PRIORITY_HIGH); builder.setLargeIcon(ImageUtils.scaleImage(largeIcon, (int) (context.getResources().getDisplayMetrics().density * 48))); builder.setColor(ChatSDK.config().pushNotificationColor); builder.setChannelId(ChatSDKMessageChannel); notificationManager.createNotificationChannel(channel); Notification notification = builder.build(); notificationManager.notify(MESSAGE_NOTIFICATION_ID, notification);
private Notification getNotification(String content) { Notification.Builder builder = new Notification.Builder(this); builder.setContentTitle(getString(R.string.app_name)); builder.setContentText(content); builder.setTicker(content); builder.setSmallIcon(R.drawable.ic_notification_appicon); builder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); builder.setDefaults(Notification.DEFAULT_VIBRATE); builder.setAutoCancel(true); builder.setLights(Color.GREEN, 500, 500); // This intent is fired when notification is clicked Intent intent = new Intent(getApplicationContext(), YouMainActvity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0); // Set the intent that will fire when the user taps the notification. builder.setContentIntent(pendingIntent); return builder.getNotification(); }
public static Notification buildNotification(Context context, Notification.Builder builder) { builder.setSmallIcon(R.drawable.leak_canary_notification) .setWhen(System.currentTimeMillis()) .setOnlyAlertOnce(true); if (SDK_INT >= O) { NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationChannel notificationChannel = notificationManager.getNotificationChannel(NOTIFICATION_CHANNEL_ID); if (notificationChannel == null) { String channelName = context.getString(R.string.leak_canary_notification_channel); notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, channelName, NotificationManager.IMPORTANCE_DEFAULT); notificationManager.createNotificationChannel(notificationChannel); } builder.setChannelId(NOTIFICATION_CHANNEL_ID); } if (SDK_INT < JELLY_BEAN) { return builder.getNotification(); } else { return builder.build(); } }
Notification.Builder builder = new Notification.Builder(this); builder.setContentTitle("Big text Notification") .setContentText("Big text Notification") .setSmallIcon(R.drawable.ic_launcher) .setAutoCancel(true) .setContentIntent(pi) // <- this new line .setPriority(Notification.PRIORITY_HIGH) .addAction(R.drawable.ic_launcher, "show activity", pi);