List of usage examples for android.app NotificationManager notify
public void notify(int id, Notification notification)
From source file:charlyn23.c4q.nyc.projectx.map.GeofenceIntentService.java
/** * Posts a notification in the notification bar when a fade_transition is detected. * If the user clicks the notification, control goes to the MainActivity. *//* w ww. j av a2 s. co m*/ private void sendNotification(String notificationDetails) { // Create an explicit content Intent that starts the main Activity. Intent notificationIntent = new Intent(this, MainActivity.class); // Get a PendingIntent containing the entire back stack. PendingIntent notificationPendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(this); // Define the notification settings. builder.setSmallIcon(R.mipmap.ic_launcher).setColor(Color.RED).setContentTitle(notificationDetails) .setContentText(getString(R.string.geofence_transition_notification_text)) .setContentIntent(notificationPendingIntent); builder.setAutoCancel(true); NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); mNotificationManager.notify(0, builder.build()); }
From source file:com.versul.newbornswatcher.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param message GCM message received./*from w w w. j a va 2 s. c o m*/ */ private void sendNotification(String message) { Intent intent = new Intent(this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.eye); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(android.R.drawable.ic_dialog_alert) .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.notification_large)) .setContentTitle("Newborns Watcher").setContentText(message).setAutoCancel(true) .setSound(defaultSoundUri).setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); }
From source file:com.airbop.client.GCMIntentService.java
/** * Issues a notification to inform the user that server has sent a message. *///from ww w. ja va 2 s. c om private static void generateNotification(Context context, String title, String message) { int icon = R.drawable.ic_stat_gcm; long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); if ((title == null) || (title.equals(""))) { title = context.getString(R.string.app_name); } Intent notificationIntent = new Intent(context, DemoActivity.class); // set intent so it does not start a new activity notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0); Notification notification = new NotificationCompat.Builder(context).setContentTitle(title) .setContentText(message).setContentIntent(intent).setSmallIcon(icon).setWhen(when) .setStyle(new NotificationCompat.BigTextStyle().bigText(message)).build(); notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0, notification); }
From source file:Main.java
public static NotificationManager showNotification(Context context, String title, String message, String alertmessage, int icon, Class<?> forwordActivity) { NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); // The PendingIntent to launch our activity if the user selects this // notification // PendingIntent contentIntent = PendingIntent.getActivity(context, 0, // new Intent(context, forwordActivity), 0); // construct the Notification object. Notification noti = new Notification(); noti.icon = icon;// w ww . j a v a 2 s . co m noti.tickerText = alertmessage; noti.when = System.currentTimeMillis(); // Set the info for the views that show in the notification panel. // noti.setLatestEventInfo(context, title, message, contentIntent); // after a 100ms delay, vibrate for 250ms, pause for 100 ms and // then vibrate for 500ms. noti.vibrate = new long[] { 100, 250, 100, 500 }; // Note that we use R.layout.incoming_message_panel as the ID for // the notification. It could be any integer you want, but we use // the convention of using a resource id for a string related to // the notification. It will always be a unique number within your // application. nm.notify(1, noti); return nm; }
From source file:budgetworld.ru.bw.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param message GCM message received./*from w w w . j a v a 2 s. co m*/ */ private void sendNotification(String message) { Intent intent = new Intent(this, MainActivity.class); //intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); intent.putExtra("from notify", message); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_stat_ic_notification).setContentTitle("BudgetWorld") .setContentText(message).setAutoCancel(true).setSound(defaultSoundUri) .setContentIntent(pendingIntent).setStyle(new NotificationCompat.BigTextStyle().bigText(message)) .setLights(getResources().getColor(R.color.led), 2000, 2000); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); }
From source file:codes.simen.l50notifications.ReminderService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { final String action = intent.getAction(); if (ACTION_REMIND.equals(action)) { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); final int reminderDelay = preferences.getInt("reminder_delay", 5000); final Bundle extras = intent.getExtras(); reminders.put(System.currentTimeMillis() + reminderDelay, extras); handler.postDelayed(displayReminder, reminderDelay); builder = new NotificationCompat.Builder(getApplicationContext()).setSmallIcon(R.drawable.ic_reminder) .setContentTitle(String.format("%d reminders", reminders.size())) .setContentText("Tap to cancel all reminders").setOngoing(true) .setPriority(NotificationCompat.PRIORITY_MIN) .setContentIntent(PendingIntent.getService(getApplicationContext(), 0, new Intent(getApplicationContext(), ReminderService.class).setAction(ACTION_STOP), PendingIntent.FLAG_UPDATE_CURRENT)); NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); notificationManager.notify(NOTIFICATION_ID, builder.build()); } else if (ACTION_STOP.equals(action)) { stopSelf();// w ww . jav a 2 s . c o m Toast.makeText(getApplicationContext(), "All reminders cancelled", Toast.LENGTH_SHORT).show(); } return START_NOT_STICKY; }
From source file:com.bayapps.android.robophish.gcm.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * */// www . j a v a 2 s. c o m private void showNotification(String title, String subtitle, String mediaId) { Intent intent = new Intent(this, MusicPlayerActivity.class); intent.putExtra(MusicPlayerActivity.EXTRA_START_FULLSCREEN, false); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); //TEST intent.setAction(MediaStore.INTENT_ACTION_MEDIA_SEARCH); intent.putExtra("title", title); intent.putExtra("subtitle", subtitle); intent.putExtra("showid", "__TRACKS_BY_SHOW__/" + mediaId); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_allmusic_black_24dp).setContentTitle("There's a new Phish show!") .setContentText(title + ", " + subtitle).setAutoCancel(true).setSound(defaultSoundUri) .setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(Integer.parseInt(mediaId), notificationBuilder.build()); }
From source file:br.ufc.quixada.dsdm.myapplicationtestemulttabs.googleGCM.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param message GCM message received./*from ww w . ja v a 2s .c o m*/ */ private void sendNotification(String message) { Intent intent = new Intent(this, MainActivityTabMensagens.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.mensageiro_icon).setContentTitle("MENSSAGEIRO").setContentText(message) .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); }
From source file:com.cc.basefunction.service.MyFirebaseMessagingService.java
/** * Create and show a simple notification containing the received FCM message. * * @param messageBody FCM message body received. *//*from w w w . ja v a 2s .c o m*/ private void sendNotification(String messageBody) { Intent intentClick = new Intent(this, NotificationBroadCast.class); intentClick.setAction("BASEFUNCTION_NOTIFICATION_CLICK"); intentClick.putExtra("message", messageBody); PendingIntent pendingIntentClick = PendingIntent.getBroadcast(this, 0, intentClick, PendingIntent.FLAG_UPDATE_CURRENT); Intent intentCancel = new Intent(this, NotificationBroadCast.class); intentCancel.setAction("BASEFUNCTION_NOTIFICATION_CANCEL"); intentCancel.putExtra("message", messageBody); PendingIntent pendingIntentCancel = PendingIntent.getBroadcast(this, 0, intentCancel, PendingIntent.FLAG_UPDATE_CURRENT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { notificationBuilder.setSmallIcon(R.drawable.notification_iocn); notificationBuilder.setColor(getResources().getColor(R.color.blue_B0E0E6)); } else { notificationBuilder.setSmallIcon(R.mipmap.ic_launcher); } notificationBuilder.setContentTitle("BaseFunction Notification").setContentText(messageBody) .setSound(defaultSoundUri).setContentIntent(pendingIntentClick) .setDeleteIntent(pendingIntentCancel); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(10086 /* ID of notification */, notificationBuilder.build()); }
From source file:com.attiqrao.systemsltd.list_to_do.AlarmReceiver.java
@Override public void onReceive(Context context, Intent intent) { int mReceivedID = Integer.parseInt(intent.getStringExtra(ReminderEditActivity.EXTRA_REMINDER_ID)); // Get notification title from Reminder Database ReminderDatabase rb = new ReminderDatabase(context); Reminder reminder = rb.getReminder(mReceivedID); String mTitle = reminder.getTitle(); // Create intent to open ReminderEditActivity on notification click Intent editIntent = new Intent(context, ReminderEditActivity.class); editIntent.putExtra(ReminderEditActivity.EXTRA_REMINDER_ID, Integer.toString(mReceivedID)); PendingIntent mClick = PendingIntent.getActivity(context, mReceivedID, editIntent, PendingIntent.FLAG_UPDATE_CURRENT); // Create Notification NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_icon)) .setSmallIcon(R.mipmap.ic_icon).setContentTitle(context.getResources().getString(R.string.app_name)) .setTicker(mTitle).setContentText(mTitle) .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM)).setContentIntent(mClick) .setAutoCancel(true).setOnlyAlertOnce(true); NotificationManager nManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); nManager.notify(mReceivedID, mBuilder.build()); }