Example usage for android.app Notification DEFAULT_SOUND

List of usage examples for android.app Notification DEFAULT_SOUND

Introduction

In this page you can find the example usage for android.app Notification DEFAULT_SOUND.

Prototype

int DEFAULT_SOUND

To view the source code for android.app Notification DEFAULT_SOUND.

Click Source Link

Document

Use the default notification sound.

Usage

From source file:nu.shout.shout.chat.ChatNotifier.java

private void applySettings() {
    int defaults = 0;
    if (this.prefs.getBoolean("noti_sound", true))
        defaults |= Notification.DEFAULT_SOUND;
    if (this.prefs.getBoolean("noti_vibrate", true))
        defaults |= Notification.DEFAULT_VIBRATE;
    if (this.prefs.getBoolean("noti_light", true))
        defaults |= Notification.DEFAULT_LIGHTS;
    this.builder.setDefaults(defaults);
}

From source file:com.commonsware.android.eventbus.otto.ScheduledService.java

@Subscribe
public void onDeadEvent(DeadEvent braiiiiiiinz) {
    RandomEvent original = (RandomEvent) braiiiiiiinz.event;
    NotificationCompat.Builder b = new NotificationCompat.Builder(this);
    Intent ui = new Intent(this, EventDemoActivity.class);

    b.setAutoCancel(true).setDefaults(Notification.DEFAULT_SOUND)
            .setContentTitle(getString(R.string.notif_title))
            .setContentText(Integer.toHexString(original.value))
            .setSmallIcon(android.R.drawable.stat_notify_more).setTicker(getString(R.string.notif_title))
            .setContentIntent(PendingIntent.getActivity(this, 0, ui, 0));

    NotificationManager mgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    mgr.notify(NOTIFY_ID, b.build());/*  w w w  .j  a  v a2  s. c  om*/
}

From source file:com.mattermost.gcm.GcmMessageHandler.java

private void createNotification(boolean doAlert) {
    Context context = getBaseContext();

    int defaults = 0;
    defaults = defaults | Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL;

    if (doAlert) {
        defaults = defaults | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND;
    }/*  w w  w. j  a v  a2s  . c o  m*/

    Intent notificationIntent = new Intent(context, SplashScreenActivity.class);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent contentIndent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

    PendingIntent deleteIntent = PendingIntent.getBroadcast(context, 0,
            new Intent(context, NotificationDismissReceiver.class), 0);

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

    if (channelIdToNotification.size() == 0) {
        mNotificationManager.cancel(MESSAGE_NOTIFICATION_ID);
        return;
    }

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.mipmap.ic_launcher).setGroup(GROUP_KEY_MESSAGES).setDefaults(defaults)
            .setContentIntent(contentIndent).setDeleteIntent(deleteIntent).setAutoCancel(true);

    if (channelIdToNotification.size() == 1) {
        Bundle data = channelIdToNotification.entrySet().iterator().next().getValue();
        String body = data.getString("message");
        mBuilder.setContentTitle("Mattermost").setContentText(body)
                .setStyle(new NotificationCompat.BigTextStyle().bigText(body));
    } else {
        NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle();

        String summaryTitle = String.format("Mattermost (%d)", channelIdToNotification.size());
        mBuilder.setContentTitle(summaryTitle);

        for (Bundle data : channelIdToNotification.values()) {
            style.addLine(data.getString("message"));
        }

        style.setBigContentTitle(summaryTitle);
        mBuilder.setStyle(style);
    }

    mNotificationManager.cancel(MESSAGE_NOTIFICATION_ID);
    mNotificationManager.notify(MESSAGE_NOTIFICATION_ID, mBuilder.build());
}

From source file:com.example.mego.adas.utils.NotificationUtils.java

/**
 * Helper Method to create and display the notification for advices
 *
 * @param context/*w  w  w . ja v a 2  s  . c o  m*/
 */
public static void remindUserWithCarAdvices(Context context) {

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
            .setColor(ContextCompat.getColor(context, R.color.colorPrimary)).setSmallIcon(R.mipmap.ic_launcher)
            .setLargeIcon(largeIcon(context))
            .setContentTitle(context.getString(R.string.notification_remind_user_advices_title))
            .setContentText(showRandomCarAdvices(context))
            .setStyle(new NotificationCompat.BigTextStyle().bigText(showRandomCarAdvices(context)))
            .setDefaults(Notification.DEFAULT_VIBRATE).setDefaults(Notification.DEFAULT_SOUND)
            .setContentIntent(contentIntent(context)).setAutoCancel(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        notificationBuilder.setPriority(Notification.PRIORITY_HIGH);
    }

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

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

From source file:com.commonsware.android.parcelable.marshall.ScheduledService.java

@Subscribe
public void onNoSubscriber(NoSubscriberEvent event) {
    RandomEvent randomEvent = (RandomEvent) event.originalEvent;
    NotificationCompat.Builder b = new NotificationCompat.Builder(this);
    Intent ui = new Intent(this, EventDemoActivity.class);

    b.setAutoCancel(true).setDefaults(Notification.DEFAULT_SOUND)
            .setContentTitle(getString(R.string.notif_title))
            .setContentText(Integer.toHexString(randomEvent.value))
            .setSmallIcon(android.R.drawable.stat_notify_more).setTicker(getString(R.string.notif_title))
            .setContentIntent(PendingIntent.getActivity(this, 0, ui, 0));

    NotificationManager mgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    mgr.notify(NOTIFY_ID, b.build());//from  w w  w .j a v  a  2  s. c  o  m
}

From source file:weekendhacks.com.kahahaibosedk.MyFirebaseMessagingService.java

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {

    // TODO(developer): Handle FCM messages here.
    // Not getting messages here? See why this may be: https://goo.gl/39bRNJ
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);

    Log.d(TAG, "From: " + remoteMessage.getFrom());

    // Check if message contains a data payload.
    if (remoteMessage.getData().size() > 0) {
        Log.d(TAG, "Message data payload: " + remoteMessage.getData());
    }//www. j  av  a 2  s  .c o  m

    // Check if message contains a notification payload.
    if (remoteMessage.getNotification() != null) {
        Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
    }

    mBuilder.setSmallIcon(R.drawable.notification_icon).setContentTitle("From :" + remoteMessage.getFrom());
    if (remoteMessage.getNotification() != null) {
        Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
        mBuilder.setContentText(remoteMessage.getNotification().getBody());
    }

    mBuilder.setDefaults(
            Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE);
    int mNotificationId = 001;
    NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    // Builds the notification and issues it.
    mNotifyMgr.notify(mNotificationId, mBuilder.build());
}

From source file:com.saarang.samples.apps.iosched.ui.debug.actions.ShowSessionNotificationDebugAction.java

@Override
public void run(Context context, Callback callback) {

    Intent i = new Intent(Intent.ACTION_VIEW, ScheduleContract.Sessions.buildSessionUri("__keynote__"));

    PendingIntent pi = PendingIntent.getActivity(context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT);
    Intent mapIntent = new Intent(context, UIUtils.getMapActivityClass(context));
    mapIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK
            | Intent.FLAG_ACTIVITY_TASK_ON_HOME);
    mapIntent.putExtra(BaseMapActivity.EXTRA_ROOM, "keynote");
    PendingIntent piMap = TaskStackBuilder.create(context).addNextIntent(mapIntent).getPendingIntent(0,
            PendingIntent.FLAG_CANCEL_CURRENT);

    //= PendingIntent.getActivity(context, 0, mapIntent, 0);

    NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(context)
            .setContentTitle("test notification").setContentText("yep, this is a test")
            .setTicker("hey, you got a test")
            .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE)
            .setSmallIcon(com.saarang.samples.apps.iosched.R.drawable.ic_stat_notification).setContentIntent(pi)
            .setPriority(Notification.PRIORITY_MAX).setAutoCancel(true);
    notifBuilder.addAction(com.saarang.samples.apps.iosched.R.drawable.ic_map_holo_dark,
            context.getString(com.saarang.samples.apps.iosched.R.string.title_map), piMap);

    NotificationCompat.InboxStyle richNotification = new NotificationCompat.InboxStyle(notifBuilder)
            .setBigContentTitle(context.getResources().getQuantityString(
                    com.saarang.samples.apps.iosched.R.plurals.session_notification_title, 1, 8, 1));

    NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    nm.notify(32534, richNotification.build());

}

From source file:com.google.samples.apps.iosched.debug.actions.ShowSessionNotificationDebugAction.java

@Override
public void run(Context context, Callback callback) {

    Intent i = new Intent(Intent.ACTION_VIEW, ScheduleContract.Sessions.buildSessionUri("__keynote__"));

    PendingIntent pi = PendingIntent.getActivity(context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT);
    Intent mapIntent = new Intent(context, MapActivity.class);
    mapIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK
            | Intent.FLAG_ACTIVITY_TASK_ON_HOME);
    mapIntent.putExtra(MapActivity.EXTRA_ROOM, "keynote");
    PendingIntent piMap = TaskStackBuilder.create(context).addNextIntent(mapIntent).getPendingIntent(0,
            PendingIntent.FLAG_CANCEL_CURRENT);

    //= PendingIntent.getActivity(context, 0, mapIntent, 0);

    NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(context)
            .setContentTitle("test notification").setContentText("yep, this is a test")
            .setTicker("hey, you got a test")
            .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE)
            .setSmallIcon(R.drawable.ic_stat_notification).setContentIntent(pi)
            .setPriority(Notification.PRIORITY_MAX).setAutoCancel(true);
    notifBuilder.addAction(R.drawable.ic_map_holo_dark, context.getString(R.string.title_map), piMap);

    NotificationCompat.InboxStyle richNotification = new NotificationCompat.InboxStyle(notifBuilder)
            .setBigContentTitle(/*from w  w  w .  j  ava 2  s  .c  o m*/
                    context.getResources().getQuantityString(R.plurals.session_notification_title, 1, 8, 1));

    NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    nm.notify(32534, richNotification.build());

}

From source file:com.grarak.cafntracker.MessagingServer.java

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    super.onMessageReceived(remoteMessage);

    String name = remoteMessage.getData().get("name");
    String title = remoteMessage.getData().get("title");
    String message = remoteMessage.getData().get("message");
    String link = remoteMessage.getData().get("link");

    if (!PreferenceManager.getDefaultSharedPreferences(this).getBoolean(name, false)) {
        return;//from w ww. j  a v  a2  s.  c  o m
    }

    String filter = PreferenceManager.getDefaultSharedPreferences(this).getString(name + "_filter", "");
    String filtertag = PreferenceManager.getDefaultSharedPreferences(this).getString(name + "_filtertag", "");
    if ((!filter.isEmpty() && !title.contains(filter))
            || (!filtertag.isEmpty() && !message.contains(filtertag))) {
        return;
    }

    Intent i = new Intent(Intent.ACTION_VIEW);
    i.setData(Uri.parse(link));

    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, i, 0);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setSmallIcon(R.mipmap.ic_launcher)
            .setContentTitle(title.isEmpty() ? name : name + ": " + title).setContentText(message)
            .setContentIntent(pendingIntent)
            .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE);

    int id = PreferenceManager.getDefaultSharedPreferences(this).getInt("notification", 0);

    NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    mNotifyMgr.notify(id, builder.build());
    PreferenceManager.getDefaultSharedPreferences(this).edit().putInt("notification", id + 1).apply();

}

From source file:com.google.samples.apps.iosched.ui.debug.actions.ShowSessionNotificationDebugAction.java

@Override
public void run(Context context, Callback callback) {

    Intent i = new Intent(Intent.ACTION_VIEW, ScheduleContract.Sessions.buildSessionUri("__keynote__"));

    PendingIntent pi = PendingIntent.getActivity(context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT);
    Intent mapIntent = new Intent(context, UIUtils.getMapActivityClass(context));
    mapIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK
            | Intent.FLAG_ACTIVITY_TASK_ON_HOME);
    mapIntent.putExtra(BaseMapActivity.EXTRA_ROOM, "keynote");
    PendingIntent piMap = TaskStackBuilder.create(context).addNextIntent(mapIntent).getPendingIntent(0,
            PendingIntent.FLAG_CANCEL_CURRENT);

    //= PendingIntent.getActivity(context, 0, mapIntent, 0);

    NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(context)
            .setContentTitle("test notification").setContentText("yep, this is a test")
            .setTicker("hey, you got a test")
            .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE)
            .setSmallIcon(R.drawable.ic_stat_notification).setContentIntent(pi)
            .setPriority(Notification.PRIORITY_MAX).setAutoCancel(true);
    notifBuilder.addAction(R.drawable.ic_map_holo_dark, context.getString(R.string.title_map), piMap);

    NotificationCompat.InboxStyle richNotification = new NotificationCompat.InboxStyle(notifBuilder)
            .setBigContentTitle(//  ww w  .ja  v a 2  s.c  om
                    context.getResources().getQuantityString(R.plurals.session_notification_title, 1, 8, 1));

    NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    nm.notify(32534, richNotification.build());

}