Example usage for android.media RingtoneManager TYPE_NOTIFICATION

List of usage examples for android.media RingtoneManager TYPE_NOTIFICATION

Introduction

In this page you can find the example usage for android.media RingtoneManager TYPE_NOTIFICATION.

Prototype

int TYPE_NOTIFICATION

To view the source code for android.media RingtoneManager TYPE_NOTIFICATION.

Click Source Link

Document

Type that refers to sounds that are used for notifications.

Usage

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.
 *//*from   www. j  a v  a2  s . com*/
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.
 *///  www. j  a va2  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.
 *///  ww w .ja v  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   www  . jav a 2 s.  c  om*/
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  w w  . ja v  a 2s. c om*/
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  w  w .j  ava  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.//  ww w . j av  a 2 s .com
 */
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 w w w .  j a  v  a 2  s  . 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());

}

From source file:com.kratav.tinySurprise.notification.MyGcmListenerService.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private Notification notificationType2() {
    Bitmap smallIconBitmap = getMeBitmap(smallIcon);
    if (smallIconBitmap == null)
        return null;

    // Constructs the Builder object.
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setContentTitle(title)
            .setTicker(title).setSubText(subtitle).setSmallIcon(R.drawable.ic_launcher)
            .setLargeIcon(smallIconBitmap).setDefaults(Notification.DEFAULT_ALL) // requires VIBRATE permission
            .setStyle(new NotificationCompat.BigTextStyle().bigText(bigMsg))
            .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
    builder.setContentIntent(pendingIntent);
    return builder.build();
}

From source file:com.tessoft.nearhere.GcmIntentService.java

private void sendNotification(Bundle extras) {

    String title = extras.getString("title");
    String type = extras.getString("type");
    String msg = extras.getString("message");

    mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher).setContentTitle(title)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg)
            .setAutoCancel(true);//w w  w  . j a va  2s.c om

    Intent intent = null;

    boolean isActive = false;

    // check if background
    //        ActivityManager activityManager = (ActivityManager) this.getSystemService( ACTIVITY_SERVICE );
    //        List<RunningAppProcessInfo> procInfos = activityManager.getRunningAppProcesses();
    //        for(int i = 0; i < procInfos.size(); i++)
    //        {
    //            if(procInfos.get(i).processName.equals("com.tessoft.nearhere")) 
    //               isActive = true;
    //        }

    // check if foreground
    ActivityManager activityManager = (ActivityManager) getApplicationContext()
            .getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningTaskInfo> services = activityManager.getRunningTasks(Integer.MAX_VALUE);

    if (services.get(0).topActivity.getPackageName().toString()
            .equalsIgnoreCase(getApplicationContext().getPackageName().toString())) {
        isActive = true;
    }

    if (isActive) {
        intent = new Intent("updateUnreadCount");
        intent.putExtra("type", type);
        if ("message".equals(type)) {
            intent.putExtra("fromUserID", extras.getString("fromUserID"));

            Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
            Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
            r.play();

            Vibrator v = (Vibrator) getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE);
            v.vibrate(500);
        } else if ("postReply".equals(type)) {
            intent.putExtra("postID", extras.getString("postID"));

            Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
            Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
            r.play();

            Vibrator v = (Vibrator) getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE);
            v.vibrate(500);
        }

        getApplicationContext().sendBroadcast(intent);
    } else {
        if ("message".equals(type)) {
            intent = new Intent(this, UserMessageActivity.class);
            HashMap hash = new HashMap();
            hash.put("fromUserID", extras.getString("fromUserID"));
            hash.put("userID", extras.getString("toUserID"));
            intent.putExtra("messageInfo", hash);
            mBuilder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI);
            mBuilder.setVibrate(new long[] { 1000, 1000 });
        } else if ("postReply".equals(type)) {
            intent = new Intent(this, TaxiPostDetailActivity.class);
            intent.putExtra("postID", extras.getString("postID"));
            mBuilder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI);
            mBuilder.setVibrate(new long[] { 1000, 1000 });
        } else if ("newPostByDistance".equals(type)) {
            intent = new Intent(this, TaxiPostDetailActivity.class);
            intent.putExtra("postID", extras.getString("postID"));
        } else if ("event".equals(type)) {
            intent = new Intent(this, EventViewerActivity.class);
            intent.putExtra("eventSeq", extras.getString("eventSeq"));
            intent.putExtra("pushNo", extras.getString("pushNo"));

            if ("on".equals(extras.getString("sound")))
                mBuilder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI);
            if ("on".equals(extras.getString("vibrate")))
                mBuilder.setVibrate(new long[] { 1000, 1000 });

        } else if ("eventssl".equals(type)) {
            intent = new Intent(this, EventViewerActivity.class);
            intent.putExtra("eventSeq", extras.getString("eventSeq"));
            intent.putExtra("pushNo", extras.getString("pushNo"));
            intent.putExtra("ssl", "true");

            if ("on".equals(extras.getString("sound")))
                mBuilder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI);
            if ("on".equals(extras.getString("vibrate")))
                mBuilder.setVibrate(new long[] { 1000, 1000 });

        } else {
            intent = new Intent(this, MainActivity.class);
        }

        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);

        mBuilder.setContentIntent(contentIntent);
        mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
    }
}