List of usage examples for android.media RingtoneManager getDefaultUri
public static Uri getDefaultUri(int type)
From source file:com.smart.taxi.GcmIntentService.java
private void sendNotification(Object msg) { Intent intent;/*from w w w .j av a2 s. com*/ String message; int rid = r.nextInt(1800 - 650) + 650; try { Bundle extras = (Bundle) msg; String notifType = (Utils.isEmptyOrNull(extras.getString("type")) && extras.getString("status").equals("1")) ? "accept" : extras.getString("type"); String journeyId = extras.getString("journey_id"); message = extras.getString("message"); intent = new Intent(DISPLAY_MESSAGE_ACTION); intent.putExtra("rid", rid); intent.putExtra("journeyId", journeyId); intent.putExtra("type", notifType); intent.putExtra("message", (Utils.isEmptyOrNull(message)) ? "" : message); getApplicationContext().sendBroadcast(intent); } catch (Exception ex) { return; } Intent notifIntent = new Intent("com.smart.taxi.beep"); notifIntent.putExtra("msg", (Utils.isEmptyOrNull(message)) ? "Beep recevied" : message); mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notifIntent, PendingIntent.FLAG_CANCEL_CURRENT); //Define sound URI Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher).setContentTitle(getString(R.string.app_name)) .setStyle(new NotificationCompat.InboxStyle().addLine(msg.toString())).setContentText(message) .setSound(soundUri).setDefaults(Notification.DEFAULT_VIBRATE); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(rid, mBuilder.build()); }
From source file:android.example.com.squawker.fcm.SquawkFirebaseMessageService.java
/** * Create and show a simple notification containing the received FCM message * * @param data Map which has the message data in it *//*from w ww . ja va 2s.com*/ private void sendNotification(Map<String, String> data) { Intent intent = new Intent(this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // Create the pending intent to launch the activity PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); String author = data.get(JSON_KEY_AUTHOR); String message = data.get(JSON_KEY_MESSAGE); // If the message is longer than the max number of characters we want in our // notification, truncate it and add the unicode character for ellipsis if (message.length() > NOTIFICATION_MAX_CHARACTERS) { message = message.substring(0, NOTIFICATION_MAX_CHARACTERS) + "\u2026"; } Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_duck) .setContentTitle(String.format(getString(R.string.notification_message), author)) .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.mohmohhtun.mapapplication.GeofenceTransitionsIntentService.java
/** * Posts a notification in the notification bar when a transition is detected. * If the user clicks the notification, control goes to the MainActivity. *//*w ww.jav a2 s . co m*/ private void sendNotification(String notificationDetails, String status) { // Create an explicit content Intent that starts the main Activity. Intent notificationIntent = new Intent(getApplicationContext(), Main.class); // Construct a task stack. TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); // Add the main Activity to the task stack as the parent. stackBuilder.addParentStack(Main.class); // Push the content Intent onto the stack. stackBuilder.addNextIntent(notificationIntent); // Get a PendingIntent containing the entire back stack. PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); // Get a notification builder that's compatible with platform versions >= 4 NotificationCompat.Builder builder = new NotificationCompat.Builder(this); // Define the notification settings. builder.setSmallIcon(R.drawable.app_icon) // In a real app, you may want to use a library like Volley // to decode the Bitmap. .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.app_icon)).setColor(Color.RED) .setSound(defaultSoundUri).setVibrate(new long[] { 1000, 1000, 1000, 1000, 1000 }) .setContentTitle(notificationDetails) .setContentText(getString(R.string.geofence_transition_notification_text)) .setContentIntent(notificationPendingIntent); // Dismiss notification once the user touches it. builder.setAutoCancel(true); // Get an instance of the Notification manager NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); // Issue the notification mNotificationManager.notify(++noti_id, builder.build()); }
From source file:com.karbide.bluoh.notification.MyFirebaseMessagingService.java
/** * Create and show a simple notification containing the received FCM message. *//*from www . j av a2 s .c o m*/ private void sendNotification(String messageBody, Bitmap image, String TrueOrFalse) { Intent intent = new Intent(this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.putExtra("AnotherActivity", TrueOrFalse); PendingIntent pendingIntent = PendingIntent.getActivity(this, 1 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) // .setLargeIcon(image)/*Notification icon image*/ .setSmallIcon(R.mipmap.ic_launcher).setContentTitle(messageBody) .setStyle(new NotificationCompat.BigPictureStyle().bigPicture(image))/*Notification with Image*/ .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(1 /* ID of notification */, notificationBuilder.build()); }
From source file:com.hidezo.app.buyer.MyFirebaseMessagingService.java
/** * Create and show a simple notification containing the received FCM message. * * @param messageBody FCM message body received. *//*from ww w . jav a2 s . c o m*/ private void sendNotification(final String messageBody, final int type_flag) { // Log.d(TAG, messageBody); final AppGlobals globals = (AppGlobals) this.getApplication(); // ??Intent? final Intent intent; // ? if (globals.getLoginState()) { // switch (type_flag) { case 1: // intent = new Intent(this, ActivityOrderes.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); break; default: // ? intent = new Intent(this, ActivitySuppliers.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); break; } } else { // ? intent = new Intent(this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); } final PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /*Request code*/, intent, PendingIntent.FLAG_ONE_SHOT); // final Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); final NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_stat_notification).setContentTitle(getString(R.string.app_name)) .setContentText(messageBody).setAutoCancel(true).setSound(defaultSoundUri) .setContentIntent(pendingIntent); // /* Add Big View Specific Configuration */ // final NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); // // // Sets a title for the Inbox style big view // inboxStyle.setBigContentTitle(messageBody); // // inboxStyle.addLine(""); // // notificationBuilder.setStyle(inboxStyle); // ------------------------------------------ // final NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /*ID of notification*/, notificationBuilder.build()); }
From source file:com.shoppingspree.shoppingspree.MyFirebaseMessagingService.java
/** * Create and show a simple notification containing the received FCM message. * * @param messageBody FCM message body received. *//*from w ww . ja v a 2 s.c o 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_stat_ic_notification).setContentTitle("Buy Through Shopping Spree") .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:chron.carlosrafael.chatapp.MyFirebaseMessagingService.java
/** * Create and show a simple notification containing the received FCM message. * * @param messageBody FCM message body received. *//*from w ww .j a v a 2 s. c o m*/ private void sendNotification(String messageBody, String messageUser) { //Se ainda nao tiver clicado na notification a ID vai ter que ser a mesma //Se tiver clicado entao temos que gerar uma nova ID int notificationID; if (NotificationHandler.createNewNotification) { Random generator = new Random(); notificationID = generator.nextInt(100); NotificationHandler.onGoingNotificationID = notificationID; //Dizendo que nao precisa criar uma nova notificacao ate o usuario clicar na notificacao e abrir o chat NotificationHandler.createNewNotification = false; } else { notificationID = NotificationHandler.onGoingNotificationID; } //Quando o usuario clicar ele vai pra o MainActivity Intent intent = new Intent(this, HomeActivity.class); //Botando um Extra para quando ele abrir por um Intent vindo do notification ele para de acumular as //mensagens de notificacao intent.putExtra("fromNotification", true); 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("New message in chat") .setContentText(messageUser + " : " + messageBody).setAutoCancel(true).setSound(defaultSoundUri) .setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); //Adicionando as mensagens no ArrayList que mantem todas as mensagens da notification que ainda vai ser vista NotificationHandler.notificationMessages.add(messageUser + " : " + messageBody); //Se nao eh pra criar uma nova notificacao entao temos que: // 1 - Adicionar essa mensagem como a ultima no ArrayList da notificacao // 2 - Ler o ArrayList pra criar o InboxStyle com todas as mensagens if (!NotificationHandler.createNewNotification) { int numMessages = NotificationHandler.notificationMessages.size(); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); String title = (numMessages > 1) ? String.valueOf(numMessages) + " new messages in chat" : String.valueOf(numMessages) + " new message in chat"; inboxStyle.setBigContentTitle(title); //inboxStyle.addLine(messageBody); for (int i = 0; i < NotificationHandler.notificationMessages.size(); i++) { //notificationBuilder.setContentText("Tamo no loop" + String.valueOf(i)) notificationBuilder.setNumber(NotificationHandler.notificationMessages.size()); inboxStyle.addLine(NotificationHandler.notificationMessages.get(i)); //inboxStyle.addLine("Tamo no loop" + String.valueOf(i)); // Because the ID remains unchanged, the existing notification is // updated. // notificationManager.notify( // notificationID, // notificationBuilder.build()); } notificationBuilder.setStyle(inboxStyle); } notificationManager.notify(notificationID, notificationBuilder.build()); // Issue the notification here. //notificationManager.notify(notificationID /* ID of notification */, notificationBuilder.build()); }
From source file:com.google.firebase.quickstart.fcm.java.MyFirebaseMessagingService.java
/** * Create and show a simple notification containing the received FCM message. * * @param messageBody FCM message body received. *//*from w ww . j a v a 2 s . c o 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_stat_ic_notification).setContentTitle(getString(R.string.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.linute.linute.API.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param data GCM Bundle received.//from w w w. j av a 2s. co m */ private void sendNotification(Bundle data, String action) { Intent intent = buildIntent(data, action); PendingIntent pendingIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), intent, PendingIntent.FLAG_ONE_SHOT); //Log.d(TAG, data.toString()); String message = data.getString("message"); //int type = gettNotificationType(data.getString("action")); //String name = data.getString("ownerFullName"); boolean isAnon = "1".equals(data.getString("privacy")); String profileImage = null; switch (action) { case "messager": try { JSONObject image = new JSONObject(data.getString("roomProfileImage")); profileImage = image.getString("original"); } catch (JSONException | NullPointerException e) { } break; default: profileImage = data.getString("ownerProfileImage"); profileImage = (isAnon ? Utils.getAnonImageUrl(String.valueOf(profileImage)) : Utils.getImageUrlOfUser(String.valueOf(profileImage))); } Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); ChatRoom chatRoom = (ChatRoom) intent.getParcelableExtra("chatRoom"); String title = chatRoom != null ? chatRoom.getRoomName() : "Tapt"; final NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_stat_untitled_4_01).setColor(Color.BLACK).setContentTitle(title) .setContentText(message).setAutoCancel(true).setSound(defaultSoundUri) .setContentIntent(pendingIntent).setStyle(new NotificationCompat.BigTextStyle().bigText(message)); if (profileImage != null) { File image = null; try { image = Glide.with(this).load(profileImage).downloadOnly(256, 256).get(); } catch (InterruptedException | ExecutionException e) { e.printStackTrace(); } if (image != null) { /*ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE); ActivityManager.MemoryInfo info = new ActivityManager.MemoryInfo(); manager.getMemoryInfo(info);*/ notificationBuilder.setLargeIcon(getCircleBitmap(image)); } } BigInteger notificationId; Object ownerId = data.get("room"); Object eventId = data.get("event"); if (eventId != null) { notificationId = new BigInteger(String.valueOf(eventId), 16); } else if (ownerId != null) { notificationId = new BigInteger(String.valueOf(ownerId), 16); } else { notificationId = BigInteger.ZERO; } final int notifId = notificationId.intValue(); Notification notifications = notificationBuilder.build(); NotificationManagerCompat.from(this).notify(notificationId.intValue(), notifications); }
From source file:com.unfc.choicecustomercare.gcmservices.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM * message.//from www . ja va 2s.c o m * * @param message GCM message received. */ 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, intent, PendingIntent.FLAG_ONE_SHOT); Intent intentAccept = new Intent(this, MainActivity.class); intent.setAction("accept"); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingAccept = PendingIntent.getActivity(this, 1, intentAccept, PendingIntent.FLAG_ONE_SHOT); // Intent intentDecline = new Intent(this, MainActivity.class); intent.setAction("decline"); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingDecline = PendingIntent.getActivity(this, 2, intentDecline, 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).setAutoCancel(false) .addAction(R.drawable.accept_ico, "Accept", pendingAccept) .addAction(R.drawable.decline_ico, "Decline", pendingDecline); notificationBuilder.getNotification().flags |= Notification.FLAG_AUTO_CANCEL; notificationBuilder.setAutoCancel(true); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify((int) new Date().getTime(), notificationBuilder.build()); }