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.pr.carjoin.chat.MyFirebaseMessagingService.java

private void showNotification(Map<String, String> payLoad, String messageBody) {
    String operationCode = payLoad.get(Util.OPERATION_CODE);
    Intent intent = new Intent(this, YourTripsActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    intent.putExtra(Util.OPERATION_CODE, payLoad.get(Util.OPERATION_CODE));
    intent.putExtra(Util.REF_PATH, payLoad.get(Util.REF_PATH));
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_launcher).setContentTitle("CarJoin").setAutoCancel(true)
            .setContentText(messageBody).setSound(defaultSoundUri).setContentIntent(pendingIntent);

    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    switch (operationCode) {
    case "5000":
        Intent acceptedIntent = new Intent(this, NotificationReceiver.class);
        Intent declinedIntent = new Intent(this, NotificationReceiver.class);
        acceptedIntent.setAction(Constants.ACCEPTED);
        acceptedIntent.putExtra("actionCode", "5000");
        acceptedIntent.putExtra(Util.REF_PATH, payLoad.get(Util.REF_PATH));
        acceptedIntent.putExtra("valueToUpdate", Constants.ACCEPTED);

        PendingIntent acceptPendingIntent = PendingIntent.getBroadcast(this, 0, acceptedIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);

        declinedIntent.setAction(Constants.REJECTED);
        declinedIntent.putExtra("actionCode", "5000");
        declinedIntent.putExtra(Util.REF_PATH, payLoad.get(Util.REF_PATH));
        declinedIntent.putExtra("valueToUpdate", Constants.REJECTED);

        PendingIntent declinePendingIntent = PendingIntent.getBroadcast(this, 0, declinedIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);

        notificationBuilder.addAction(R.drawable.decline, "Decline", declinePendingIntent);
        notificationBuilder.addAction(R.drawable.accept, "Accept", acceptPendingIntent);
        notificationManager.notify(5000, notificationBuilder.build());
        break;/*ww  w. j a v  a  2  s.  com*/
    }

}

From source file:com.example.llh_pc.it_support.gcm.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
        /*from w  w w. ja va2s. co  m*/
 */
private void sendNotification(String message, String avatar, String name) {
    Intent intent = new Intent(this, frmTabHost.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.its_logo_72x72px).setContentTitle("IT Support").setContentText(name)
            .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent);
    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    notificationManager.notify(++Flags.number_notification /* ID of notification */,
            notificationBuilder.build());
}

From source file:com.belatrix.events.utils.fcm.EventsFirebaseMessagingService.java

private void sendNotification(String messageTitle, String messageBody) {
    Intent intent = MainActivity.makeIntent(this);
    intent.putExtra(MainActivity.PARAM_FROM_NOTIFICATION, true);
    intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT);

    NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle();
    bigTextStyle.setBigContentTitle(messageTitle);
    bigTextStyle.bigText(messageBody);/*from  w w w  .  ja va2 s  .  c  om*/

    Bitmap icon = BitmapFactory.decodeResource(getApplicationContext().getResources(), R.drawable.ic_launcher);

    Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.bx_connect_white).setLargeIcon(icon).setStyle(bigTextStyle)
            .setContentText(messageBody).setContentTitle(messageTitle).setAutoCancel(true)
            .setContentIntent(pendingIntent).setSound(alarmSound).setLights(0xFF8F0300, 1000, 200)
            .setPriority(Notification.PRIORITY_MAX);

    //for vibration
    Vibrator v = (Vibrator) getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE);
    v.vibrate(1000);

    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    long time = new Date().getTime();
    String tmpStr = String.valueOf(time);
    String last4Str = tmpStr.substring(tmpStr.length() - 5);
    int notificationId = Integer.valueOf(last4Str);

    notificationManager.notify(notificationId, notificationBuilder.build());
}

From source file:com.cfc.needblood.GCMIntentService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 *///from  w  w w . ja v  a  2s  . c  o m
private static void generateNotification(Context context, String message) {
    long when = System.currentTimeMillis();

    Intent notificationIntent = new Intent(context, MainActivity.class);
    // set intent so it does not start a new activity
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);

    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);

    // Change the icons to conform Android's design guildeline
    builder.setContentIntent(contentIntent).setSmallIcon(R.drawable.ic_launcher)
            .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.bd_icon))
            .setTicker(message).setWhen(when).setAutoCancel(true)
            .setContentTitle(context.getString(R.string.app_name))
            .setContentText(context.getString(R.string.notification_message));

    Notification notification = builder.build();

    notificationManager.notify(0, notification);

    // Notification sound, comment out if do not need
    Uri ringtone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    Ringtone r = RingtoneManager.getRingtone(context, ringtone);
    r.play();
}

From source file:com.lvbo.template.module.fcm.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received.// www  .jav  a 2 s . c  o m
 */
private void sendNotification(String message) {
    Intent intent = new Intent(this, MainActivity.class);

    //        intent.setData((Uri.parse("custom://"+ System.currentTimeMillis()))); // For multiple notification

    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    int bgColor = getResources().getColor(R.color.colorPrimary);
    Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_launcher).setLargeIcon(largeIcon)
            .setContentTitle(getString(R.string.app_name)).setContentText(message)
            //                .setAutoCancel(true)
            .setSound(defaultSoundUri).setContentIntent(pendingIntent).setColor(bgColor)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(message));

    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    notificationManager.notify(notificationId /* ID of notification */, notificationBuilder.build());
    notificationId++;
}

From source file:be.ehb.fallwear.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received./*  w  w w .ja  v  a 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 = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_stat_ic_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.rip.roomies.service.MessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param message FCM message body received.
 *//*from w  w  w .j  ava 2  s.  c om*/
private void sendNotification(String title, String message) {

    Intent intent;
    if (MyApplication.isActivityVisible()) {
        switch (title) {
        case "Duty Completion":
        case "Duty Reminder":
            intent = new Intent(this, ListAllDuties.class);
            break;
        case "Shared Item Completion":
        case "Shared Item Reminder":
            intent = new Intent(this, ListAllGoods.class);
            break;
        case "Bill Reminder":
            intent = new Intent(this, Bills.class);
            break;
        default:
            intent = new Intent(this, Home.class);
        }
    } else {
        intent = new Intent(this, SplashScreen.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)
            .setLargeIcon((BitmapFactory.decodeResource(this.getResources(), R.mipmap.ic_launcher)))
            .setContentTitle(title).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:de.nitri.aptimob.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received./*from w  ww .ja va2 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_ic_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());*/

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.icon_notification_bubble).setContentTitle(getString(R.string.app_name))
            .setContentText(message).setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
            .setDefaults(Notification.DEFAULT_VIBRATE).setTicker(message);
    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(this, AptiMob.class);
    resultIntent.putExtra("newMessage", true);

    // The stack builder object will contain an artificial back stack for
    // the
    // started Activity.
    // This ensures that navigating backward from the Activity leads out of
    // your application to the Home screen.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(AptiMobMain.class);
    // Adds the Intent that starts the Activity to the top of the stack
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    // mId allows you to update the notification later on.
    mNotificationManager.notify(0, mBuilder.build());
}

From source file:com.sendbird.android.CS185Project.fcm.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 *//*  w  w  w.j  a  v 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);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.sendbird_ic_launcher).setContentTitle("SendBird")
            .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.maxwen.wallpaper.firebase.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 *///from  w  ww  . j a va  2 s  .c  o  m
private void sendNotification(String messageBody) {
    Intent intent = new Intent(this, WallpaperBoardActivity.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_drawer_wallpapers).setContentTitle("FCM Message")
            .setContentText(messageBody).setAutoCancel(true).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}