List of usage examples for android.media RingtoneManager TYPE_NOTIFICATION
int TYPE_NOTIFICATION
To view the source code for android.media RingtoneManager TYPE_NOTIFICATION.
Click Source Link
From source file:com.nuig.trafficapp.MyGcmListenerService.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.drawable.ic_warning_white_24dp).setContentTitle("RoadViser") .setContentText("New Incident: " + 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.instify.android.services.MyFirebaseMessagingService.java
/** * Create and show a simple notification containing the received FCM message. * * @param messageBody FCM message body received. *///from w w w.j a va 2 s . co m private void sendNotification(String messageBody) { 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); String channelId = getString(R.string.default_notification_channel_id); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, channelId) .setSmallIcon(R.drawable.ic_notification_white).setContentTitle("FCM Message") .setContentText(messageBody).setAutoCancel(true).setSound(defaultSoundUri) .setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); // Since android Oreo notification channel is needed. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationChannel channel = new NotificationChannel(channelId, "Channel human readable title", NotificationManager.IMPORTANCE_DEFAULT); notificationManager.createNotificationChannel(channel); } notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); }
From source file:com.example.notification.gcm.GcmIntentService.java
private void sendNotification(String msg) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); // get a resource's Uri String soundPath = "android.resource://" + getPackageName() + "/" + R.raw.sound; Uri soundURI = Uri.parse(soundPath); try {/*from w w w. j a va 2 s .com*/ Intent ourIntent = new Intent(GcmIntentService.this, Message1.class); ourIntent.putExtra("GCM", body); ourIntent.putExtra("FROM", notifier); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, ourIntent, PendingIntent.FLAG_ONE_SHOT); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.a3) .setContentTitle("GCM Notification").setAutoCancel(true) .setVibrate(new long[] { 1000, 1000, 1000, 1000 }).setSound(soundURI) .setWhen(System.currentTimeMillis()) .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg); mBuilder.setContentIntent(contentIntent); // mBuilder mNotificationManager.notify(0, mBuilder.build()); } catch (Exception e) { e.printStackTrace(); } }
From source file:de.enlightened.peris.MailService.java
private void processUnreadMessage(final InboxItem ii, final long idServer) { final SQLiteDatabase db = this.dbHelper.getWritableDatabase(); if (MessageNotificationRepository.findOneByServerAndMessage(db, idServer, Integer.parseInt(ii.messageId)) == null) { String notificationColor = getString(R.string.default_color); final String customColor = this.mailSession.getServer().serverColor; if (customColor.contains("#")) { notificationColor = customColor; }// ww w. jav a 2 s . co m final Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); final long[] pattern = { 500, 500, 500, 500, 500, 500, 500, 500, 500 }; final NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(MailService.this) .setSmallIcon(R.drawable.ic_launcher).setContentTitle("New Message From " + ii.sender) .setContentText(ii.subject).setSound(alarmSound) .setLights(Color.parseColor(notificationColor), LED_ON_MS, LED_OFF_MS).setVibrate(pattern) .setAutoCancel(true); final Intent resultIntent = new Intent(MailService.this, MessageActivity.class); final Bundle bundle = new Bundle(); bundle.putString("id", (String) ii.messageId); bundle.putString("boxid", (String) "0"); bundle.putString("name", (String) ii.subject); bundle.putString("moderator", (String) ii.senderId); bundle.putString("background", (String) notificationColor); bundle.putString("server", this.mailSession.getServer().serverId); resultIntent.putExtras(bundle); final TaskStackBuilder stackBuilder = TaskStackBuilder.create(MailService.this); stackBuilder.addParentStack(MessageActivity.class); stackBuilder.addNextIntent(resultIntent); String flag = ii.messageId; if (flag.length() > 5) { flag = flag.substring(flag.length() - 5, flag.length()); } final PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(Integer.parseInt(flag), PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); final NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); mNotificationManager.notify(Integer.parseInt(ii.messageId), mBuilder.build()); MessageNotificationRepository.add(db, new MessageNotification(idServer, Integer.parseInt(ii.messageId))); } }
From source file:com.example.sam.drawerlayoutprac.Partner.MyFirebaseMessagingService.java
/** * Create and show a simple notification containing the received FCM message. * * @param aNotificationMsgBody FCM message body received. */// ww w .j a v a2 s . co m private void sendNotification(String aNotificationMsgBody, Map<String, String> aDataMap) { Intent intent = new Intent(this, MainActivity.class); //?data-MainActivity.class -> ?bundle?("fcm")??: Set<String> keys = aDataMap.keySet(); Bundle bundle = null; for (String key : keys) { bundle = new Bundle(); bundle.putString(key, aDataMap.get(key)); } intent.putExtras(bundle); // ?Notification: 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); String fromMemId = aDataMap.get("fromMemId"); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.logo03_64dp).setColor(getResources().getColor(R.color.sub1_color)) .setContentTitle("DDD hotel").setContentText(aNotificationMsgBody).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.bigbug.android.pp.gcm.GCMIntentService.java
/** * Create and show a simple notification containing the received GCM message. * * @param message GCM message received.//from w ww . j a va2s . c om */ 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.example.mobileid.GcmIntentService.java
private void sendNotification(Intent intent) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); Bundle extras = intent.getExtras();// w w w. j a v a 2 s. c o m JSONObject gcmObj; try { gcmObj = new JSONObject(extras.getString("message")); String msg = gcmObj.getString("info"); Intent passIntent = new Intent(); passIntent.setClass(this, MainActivity.class); passIntent.putExtra("gcmMsg", gcmObj.toString()); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, passIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this); if (msg.compareToIgnoreCase("websign") != 0) { // NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) mBuilder.setSmallIcon(R.drawable.ic_launcher).setContentTitle("mobileID") .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg); } else { // NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) mBuilder.setSmallIcon(R.drawable.ic_launcher) .setContentTitle("Web Sign - " + gcmObj.getString("title")) .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)) .setContentText(gcmObj.getString("content")); } //default notification sound Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); mBuilder.setSound(alarmSound); //cleared after clicking mBuilder.setAutoCancel(true); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.gsma.rcs.ri.sharing.geoloc.GeolocSharingIntentService.java
/** * Add geoloc share notification// w w w. ja va 2 s . c o m * * @param invitation intent */ private void addGeolocSharingInvitationNotification(Intent invitation, ContactId contact) { /* Create pending intent */ Intent intent = new Intent(invitation); intent.setClass(this, ReceiveGeolocSharing.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); /* * If the PendingIntent has the same operation, action, data, categories, components, and * flags it will be replaced. Invitation should be notified individually so we use a random * generator to provide a unique request code and reuse it for the notification. */ int uniqueId = Utils.getUniqueIdForPendingIntent(); PendingIntent contentIntent = PendingIntent.getActivity(this, uniqueId, intent, PendingIntent.FLAG_ONE_SHOT); String displayName = RcsContactUtil.getInstance(this).getDisplayName(contact); String title = getString(R.string.title_recv_geoloc_sharing); /* Create notification */ NotificationCompat.Builder notif = new NotificationCompat.Builder(this); notif.setContentIntent(contentIntent); notif.setSmallIcon(R.drawable.ri_notif_csh_icon); notif.setWhen(System.currentTimeMillis()); notif.setAutoCancel(true); notif.setOnlyAlertOnce(true); notif.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); notif.setDefaults(Notification.DEFAULT_VIBRATE); notif.setContentTitle(title); notif.setContentText(getString(R.string.label_from_args, displayName)); /* Send notification */ NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(uniqueId, notif.build()); }
From source file:com.preguardia.app.notification.MyGcmListenerService.java
private void showConsultationClosedNotification(String title, String message, String consultationId) { // Prepare intent which is triggered if the notification is selected Intent intent = new Intent(this, ConsultationDetailsActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.putExtra(Constants.EXTRA_CONSULTATION_ID, consultationId); PendingIntent pendingIntent = PendingIntent.getActivity(this, Constants.PATIENT_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_logo).setContentTitle(title).setContentText(message) .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(5, notificationBuilder.build()); }
From source file:com.vanity.mobilevanity.gcm.MyGcmListenerService.java
private void sendNotification(Notify notify) { Intent intent = new Intent(this, BeautyTipDetailActivity.class); intent.putExtra(BeautyTipDetailActivity.TAG_BEAUTY_TIP_ID, notify.getBeautyTipId().getKey().getRaw().getId()); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); int bgColor = MyApplication.getContext().getResources().getColor(R.color.colorMain); BitmapDrawable drawable = (BitmapDrawable) MyApplication.getContext().getResources() .getDrawable(R.drawable.vanity_logo_big); Bitmap appIcon = drawable.getBitmap(); int smallIconId; if (notify.getType().equals("comment")) smallIconId = R.drawable.icon_notify_comment; else/* ww w .j av a 2 s . c om*/ smallIconId = R.drawable.icon_notify_like; Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this).setLargeIcon(appIcon) .setSmallIcon(smallIconId).setColor(bgColor).setTicker("GCM Message").setContentTitle("Vanity") .setContentText(notify.getMessage()).setAutoCancel(true).setSound(defaultSoundUri) .setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); }