List of usage examples for android.app NotificationManager notify
public void notify(int id, Notification notification)
From source file:br.com.bign.push.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param message GCM message received./* w ww . ja va 2 s. com*/ */ private void sendNotification(String message, String title) { 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 = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.ic_launcher).setContentTitle(title).setContentText(message) .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); Random random = new Random(); notificationManager.notify(random.nextInt(), notificationBuilder.build()); }
From source file:com.app.ntuc.notifs.MyGcmListenerService.java
private void sendNotifications(String messageBody) { Intent intent = new Intent(this, MainActivity2_.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.mipmap.ic_launcher).setContentTitle("KPMG").setContentText(messageBody) .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.android.talkbacktests.testsession.NotificationTest.java
private void showTickerNotification() { NotificationCompat.Builder builder = new NotificationCompat.Builder(getContext()) .setSmallIcon(android.R.drawable.stat_notify_more).setAutoCancel(true) .setContentTitle(getString(R.string.ticker_notification_title)) .setContentText(getString(R.string.ticker_notification_text)) .setTicker(getString(R.string.ticker_notification_ticker)) .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); NotificationManager notificationManager = (NotificationManager) getContext() .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(NOTIFICATION_ID_MAIN_MENU, builder.build()); }
From source file:com.appsaur.tarucassist.AlarmReceiver.java
@Override public void onReceive(Context context, Intent intent) { int mReceivedID = Integer.parseInt(intent.getStringExtra(BaseActivity.EXTRA_REMINDER_ID)); // Get notification title from Reminder Database ScheduleReminderDataSource scheduleReminderDataSource = new ScheduleReminderDataSource(context); StudentScheduleDataSource studentScheduleDataSource = new StudentScheduleDataSource(context); studentScheduleDataSource.open();/*from ww w . j a va 2s .com*/ ScheduleReminder scheduleReminder = scheduleReminderDataSource.getScheduleReminder(mReceivedID); String mTitle = scheduleReminder.getTitle(); int scheduleId = scheduleReminder.getScheduleId(); mCalendar = Calendar.getInstance(); String scheduleDate = studentScheduleDataSource.getCancelledScheduleById(scheduleId, BaseActivity.dateFormat.format(mCalendar.getTime())); if (!scheduleDate.equals("")) mTitle = mTitle + " - Cancelled"; // Create intent to open ReminderEditActivity on notification click Intent editIntent = new Intent(context, ViewScheduleActivity.class); editIntent.putExtra(BaseActivity.KEY_SCHEDULE_ID, Integer.toString(scheduleId)); 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_launcher)) .setSmallIcon(R.drawable.ic_timetable_white) .setContentTitle(context.getResources().getString(R.string.app_name)).setTicker(mTitle) .setContentText(mTitle).setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)) .setContentIntent(mClick).setAutoCancel(true).setOnlyAlertOnce(true); NotificationManager nManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); nManager.notify(mReceivedID, mBuilder.build()); }
From source file:com.bigbug.android.pp.gcm.GCMIntentService.java
/** * Create and show a simple notification containing the received GCM message. * * @param message GCM message received./* www.jav a2 s . com*/ */ 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 = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_stat_notification).setContentTitle("GCM Message") .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.company.millenium.iwannask.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param data GCM message received.// w w w. ja v a 2 s. c o m */ private void sendNotification(Bundle data) { String question_body = data.getString("question_body"); String answer_body = data.getString("answer_body"); String question_id = data.getString("question_id"); //String answer_id = data.getString("answer_id"); String user_name = data.getString("user_name"); if (user_name != null && user_name.contains(" ")) { user_name = user_name.split(" ")[0]; } String type = data.getString("type"); Intent intent = new Intent(this, MainActivity.class); intent.putExtra("url", "/questions/" + question_id); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_CANCEL_CURRENT); String info = " answered:"; if (type != null && type.contentEquals("answer_feedback")) { String isLiked = data.getString("feedback_value"); info = " disliked your answer"; if (isLiked != null && isLiked.equals("true")) { info = " liked your answer"; } } else if (type != null && type.contentEquals("question_answer_op")) { info = " commented on"; } Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_comment_question_outline_grey600_36dp).setContentTitle(user_name + info) .setContentText(question_body) .setStyle(new NotificationCompat.BigTextStyle().bigText(question_body + "\n" + answer_body)) .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(id, notificationBuilder.build()); id = id + 1; }
From source file:com.app.basarnas.fcm.MyFirebaseMessagingService.java
private void sendNotification() { Intent intent = new Intent(this, MainActivity.class); intent.putExtra(Config.JSON_DATA_NOTIFICATION, jsonDataNotification); intent.setAction(Intent.ACTION_MAIN); 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) .setStyle(new NotificationCompat.BigTextStyle().bigText(dataNotification.getText())) .setSmallIcon(R.mipmap.ic_launcher, 10) .setColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary)) .setContentTitle(dataNotification.getTitle()) .setContentText(CommonUtilities.toHtml(dataNotification.getText())) .setPriority(NotificationCompat.PRIORITY_HIGH).setAutoCancel(true).setSound(defaultSoundUri) .setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(Config.NOTIFICATION_ID /* ID of notification */, notificationBuilder.build()); }
From source file:com.app.infideap.postingapp.service.MyFirebaseMessagingService.java
/** * Create and show a simple notification containing the received FCM message. *///w w w .ja v a2 s .c o m private void sendNotification(RemoteMessage remoteMessage) { // Toast.makeText(getApplication(), "Received", Toast.LENGTH_SHORT).show(); Notification notification = null; if (remoteMessage.getData() != null) notification = saveData(remoteMessage); else if (remoteMessage.getNotification() != null) notification = save(remoteMessage); if (notification == null) return; 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 = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.ic_launcher).setContentTitle(notification.title) .setContentText(notification.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.aluvi.android.services.push.AluviPushNotificationListenerService.java
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 = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.ic_launcher).setContentTitle(getString(R.string.app_name)) .setContentText(message).setAutoCancel(true).setSound(defaultSoundUri) .setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build()); }
From source file:com.android.settings.sim.SimSelectNotification.java
private void createNotification(Context context) { final Resources resources = context.getResources(); NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_sim_card_alert_white_48dp) .setColor(context.getColor(R.color.sim_noitification)) .setContentTitle(resources.getString(R.string.sim_notification_title)) .setContentText(resources.getString(R.string.sim_notification_summary)); Intent resultIntent = new Intent(context, SimSettingsActivity.class); resultIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, PendingIntent.FLAG_CANCEL_CURRENT); builder.setContentIntent(resultPendingIntent); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(NOTIFICATION_ID, builder.build()); }