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:com.google.android.apps.paco.NotificationCreator.java

private Notification createNotification(Context context, Experiment experiment,
        NotificationHolder notificationHolder, String message) {
    int icon = R.drawable.paco32;

    String tickerText = context.getString(R.string.time_for_notification_title) + experiment.getTitle();
    if (notificationHolder.isCustomNotification()) {
        tickerText = message;// w  w  w  .j a v  a  2  s. com
    }

    //Notification notification = new Notification(icon, tickerText, notificationHolder.getAlarmTime());

    Intent surveyIntent = new Intent(context, ExperimentExecutor.class);
    surveyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    Uri uri = Uri.withAppendedPath(ExperimentColumns.JOINED_EXPERIMENTS_CONTENT_URI,
            experiment.getId().toString());
    surveyIntent.setData(uri);
    surveyIntent.putExtra(Experiment.SCHEDULED_TIME, notificationHolder.getAlarmTime());
    surveyIntent.putExtra(NOTIFICATION_ID, notificationHolder.getId().longValue());

    PendingIntent notificationIntent = PendingIntent.getActivity(context, 1, surveyIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    // new wearable compatible way to do it
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context).setSmallIcon(icon)
            .setContentTitle(experiment.getTitle()).setTicker(tickerText).setContentText(message)
            .setWhen(notificationHolder.getAlarmTime()).setContentIntent(notificationIntent)
            .setAutoCancel(true);

    int defaults = Notification.DEFAULT_VIBRATE | Notification.DEFAULT_LIGHTS;
    String ringtoneUri = new UserPreferences(context).getRingtone();
    if (ringtoneUri != null) {
        notificationBuilder.setSound(Uri.parse(ringtoneUri));
    } else {
        defaults |= Notification.DEFAULT_SOUND;
        //    notification.sound = Uri.parse(android.os.Environment.getExternalStorageDirectory().getAbsolutePath()
        //                                   + "/Android/data/" + context.getPackageName() + "/" +
        //                                   "deepbark_trial.mp3");
    }
    notificationBuilder.setDefaults(defaults);

    //end wearable

    return notificationBuilder.build();
}

From source file:gwind.windalarm.MyFirebaseMessagingService.java

public static void xnotifyUser(Context context, String header, String message, String spotId) {

    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Activity.NOTIFICATION_SERVICE);
    Intent notificationIntent = new Intent(context.getApplicationContext(), SplashActivity.class);

    notificationIntent.putExtra("spotId", spotId);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    stackBuilder.addParentStack(MainActivity.class);
    stackBuilder.addNextIntent(notificationIntent);
    PendingIntent pIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

    Notification notification = new Notification.Builder(context).setContentTitle(header)
            .setContentText(message).setContentIntent(pIntent)
            .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE).setContentIntent(pIntent)
            .setAutoCancel(true).setSmallIcon(R.drawable.logo).build();

    // mId allows you to update the notification later on.
    int mId = 2;/* w  w w.  j  a  v a 2  s.  c  o  m*/
    notificationManager.notify(mId, notification);
}

From source file:com.twofours.surespot.services.SurespotGcmListenerService.java

private void generateNotification(Context context, String type, String from, String to, String title,
        String message, String tag, int id) {
    SurespotLog.d(TAG, "generateNotification");
    // get shared prefs
    SharedPreferences pm = context.getSharedPreferences(to, Context.MODE_PRIVATE);
    if (!pm.getBoolean("pref_notifications_enabled", true)) {
        return;/*from   ww  w  .ja  v  a 2s  .c  o m*/
    }

    int icon = R.drawable.surespot_logo;

    // need to use same builder for only alert once to work:
    // http://stackoverflow.com/questions/6406730/updating-an-ongoing-notification-quietly
    mBuilder.setSmallIcon(icon).setContentTitle(title).setAutoCancel(true).setOnlyAlertOnce(false)
            .setContentText(message);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);

    Intent mainIntent = null;
    mainIntent = new Intent(context, MainActivity.class);
    mainIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    mainIntent.putExtra(SurespotConstants.ExtraNames.MESSAGE_TO, to);
    mainIntent.putExtra(SurespotConstants.ExtraNames.MESSAGE_FROM, from);
    mainIntent.putExtra(SurespotConstants.ExtraNames.NOTIFICATION_TYPE, type);

    stackBuilder.addNextIntent(mainIntent);

    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent((int) new Date().getTime(),
            PendingIntent.FLAG_CANCEL_CURRENT);

    mBuilder.setContentIntent(resultPendingIntent);
    int defaults = 0;

    boolean showLights = pm.getBoolean("pref_notifications_led", true);
    boolean makeSound = pm.getBoolean("pref_notifications_sound", true);
    boolean vibrate = pm.getBoolean("pref_notifications_vibration", true);
    int color = pm.getInt("pref_notification_color", getResources().getColor(R.color.surespotBlue));

    if (showLights) {
        SurespotLog.v(TAG, "showing notification led");
        mBuilder.setLights(color, 500, 5000);
        defaults |= Notification.FLAG_SHOW_LIGHTS; // shouldn't need this - setLights does it.  Just to make sure though...
    } else {
        mBuilder.setLights(color, 0, 0);
    }

    if (makeSound) {
        SurespotLog.v(TAG, "making notification sound");
        defaults |= Notification.DEFAULT_SOUND;
    }

    if (vibrate) {
        SurespotLog.v(TAG, "vibrating notification");
        defaults |= Notification.DEFAULT_VIBRATE;
    }

    mBuilder.setDefaults(defaults);
    mNotificationManager.notify(tag, id, mBuilder.build());
}

From source file:com.landenlabs.all_devtool.PackageFragment.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received.//from  w  w  w. j  av  a  2 s.co m
 */
private void sendNotification(Context context, String from, String message) {
    /*
    Intent intent = new Intent(context, DevToolActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent,
        PendingIntent.FLAG_ONE_SHOT);
    */

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.shortcut_pkg).setContentTitle("Uninstalled").setContentText(message)
            .setAutoCancel(true);
    //       .setVibrate(new long[] { 1000, 1000, 1000, 1000, 1000 })
    //       .setLights(Color.RED, 3000, 3000)
    //       .setSound(defaultSoundUri)
    //       .setSound(Settings.System.DEFAULT_NOTIFICATION_URI)
    //       .setContentIntent(pendingIntent);

    // <uses-permission android:name="android.permission.VIBRATE" />

    Notification note = notificationBuilder.build();
    note.defaults |= Notification.DEFAULT_VIBRATE;
    note.defaults |= Notification.DEFAULT_SOUND;
    note.defaults |= Notification.DEFAULT_LIGHTS;

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

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

From source file:am.roadpolice.roadpolice.alarm.AlarmReceiver.java

@Override
public void submissionCompleted(ArrayList<ViolationInfo> list, String result) {
    // If errors occurs while trying to update data.
    if (!TextUtils.isEmpty(result)) {
        final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext);
        SharedPreferences.Editor ed = sp.edit();
        ed.putBoolean(MainActivity.MISS_UPDATE_DUE_TO_NETWORK_ISSUE, true);
        ed.apply();//from w  ww  . j a va  2s  .  c  o  m
        return;
    }

    SQLiteHelper dbHelper = new SQLiteHelper(mContext);
    // Get list of new violation info, if null no new items found.
    ArrayList<ViolationInfo> newViolationInfoList = dbHelper.insertViolationInfoListAndCheckNew(list);

    // Create notification.
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mContext);
    // Create notification Title Text.
    int updateInterval = DialogSettings.getUpdateInterval(mContext);
    switch (updateInterval) {
    case DialogSettings.DAILY:
        mBuilder.setContentTitle(mContext.getString(R.string.txtDailyNotification));
        break;

    case DialogSettings.WEEKLY:
        mBuilder.setContentTitle(mContext.getString(R.string.txtWeeklyNotification));
        break;

    case DialogSettings.MONTHLY:
        mBuilder.setContentTitle(mContext.getString(R.string.txtMonthlyNotification));
        break;
    }

    // Create notification message.
    if (newViolationInfoList == null || newViolationInfoList.size() < 1) {
        mBuilder.setContentText(mContext.getString(R.string.txtNoViolationNotification));
        mBuilder.setSmallIcon(R.drawable.ic_checked);
    } else {
        mBuilder.setContentText(mContext.getString(R.string.txtYesViolationNotification));
        mBuilder.setSmallIcon(R.drawable.ic_attention);
    }

    // Activate vibration and sound.
    mBuilder.setDefaults(Notification.DEFAULT_SOUND);
    mBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
    mBuilder.setAutoCancel(true);

    // Set intent to open Main Activity, when user click on notification.
    Intent notificationIntent = new Intent(mContext, MainActivity.class);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent mainActivityPendingIntent = PendingIntent.getActivity(mContext, 0, notificationIntent, 0);

    mBuilder.setContentIntent(mainActivityPendingIntent);

    // Show notification.
    NotificationManager mNotificationManager = (NotificationManager) mContext
            .getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(0, mBuilder.build());

    // Get shared preferences.
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext);
    SharedPreferences.Editor ed = sp.edit();
    ed.putBoolean(MainActivity.MISS_UPDATE_DUE_TO_NETWORK_ISSUE, false);
    ed.apply();

}

From source file:com.twofours.surespot.services.SurespotGcmListenerService.java

private void generateSystemNotification(Context context, String title, String message, String tag, int id) {

    // need to use same builder for only alert once to work:
    // http://stackoverflow.com/questions/6406730/updating-an-ongoing-notification-quietly
    mBuilder.setAutoCancel(true).setOnlyAlertOnce(true);

    int defaults = 0;

    mBuilder.setLights(0xff0000FF, 500, 5000);
    defaults |= Notification.DEFAULT_SOUND;
    defaults |= Notification.DEFAULT_VIBRATE;

    mBuilder.setDefaults(defaults);//from   w  w  w. ja v a 2 s . c  o  m

    PendingIntent contentIntent = PendingIntent.getActivity(context, (int) new Date().getTime(), new Intent(),
            PendingIntent.FLAG_CANCEL_CURRENT);

    Notification notification = UIUtils.generateNotification(mBuilder, contentIntent, getPackageName(), title,
            message);

    mNotificationManager.notify(tag, id, notification);
}

From source file:com.android.talkback.TalkBackUpdateHelper.java

private Notification buildGestureChangeNotification(Intent clickIntent) {
    final PendingIntent pendingIntent = PendingIntent.getActivity(mService, 0, clickIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    final String ticker = mService.getString(R.string.notification_title_talkback_gestures_changed);
    final String contentTitle = mService.getString(R.string.notification_title_talkback_gestures_changed);
    final String contentText = mService.getString(R.string.notification_message_talkback_gestures_changed);
    final Notification notification = new NotificationCompat.Builder(mService)
            .setSmallIcon(R.drawable.ic_stat_info).setTicker(ticker).setContentTitle(contentTitle)
            .setContentText(contentText).setContentIntent(pendingIntent).setAutoCancel(false).setWhen(0)
            .build();//from  w  w  w  .  ja v  a2 s.  c  om

    notification.defaults |= Notification.DEFAULT_SOUND;
    notification.flags |= Notification.FLAG_ONGOING_EVENT;
    return notification;
}

From source file:io.coldstart.android.GCMIntentService.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void SendInboxStyleNotification(String alertCount, String alertTime, String hostname,
        String payloadDetails) {//  w  w w .  ja v a 2 s . co m
    Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    String Line1 = "", Line2 = "", Line3 = "", Line4 = "", Line5 = "";
    String[] separatedLines = payloadDetails.split("\n");

    int payloadLength = separatedLines.length;
    if (payloadLength > 5)
        payloadLength = 5;

    for (int i = 0; i < payloadLength; i++) {
        try {
            switch (i) {
            case 0: {
                Line1 = separatedLines[i];
            }
                break;

            case 1: {
                Line2 = separatedLines[i];
            }
                break;

            case 2: {
                Line3 = separatedLines[i];
            }
                break;

            case 3: {
                Line4 = separatedLines[i];
            }
                break;

            case 4: {
                Line5 = separatedLines[i];
            }
                break;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    Notification notification = new Notification.InboxStyle(
            new Notification.Builder(this).setContentTitle("SNMP trap received")
                    .setContentText(Line1 + " " + Line2 + "...").setSmallIcon(R.drawable.ic_stat_alert)
                    .setVibrate(new long[] { 0, 100, 200, 300 }).setAutoCancel(true).setSound(uri)
                    .setPriority(Notification.PRIORITY_MAX).setTicker("New SNMP traps have been received")
                    .setContentIntent(PendingIntent.getActivity(this, 0,
                            new Intent(this, TrapListActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
                                    .putExtra("forceRefresh", true),
                            0))).setBigContentTitle("New SNMP traps have been received")
                                    .setSummaryText("Launch ColdStart.io to Manage These Events").addLine(Line1)
                                    .addLine(Line2).addLine(Line3).addLine(Line4).build();

    notification.defaults |= Notification.DEFAULT_SOUND;

    mNM.notify(43523, notification);
}

From source file:nl.dobots.presence.PresenceDetectionApp.java

private void onNetworkError(String error, boolean present, String location, String additionalInfo) {

    // only trigger notification once as long as the network error is active.
    if (!_networkErrorActive) {
        _networkErrorActive = true;/*from ww w  .ja  va2s  .  com*/

        if (_settings.isNotificationsEnabled()) {
            Intent contentIntent = new Intent(this, MainActivity.class);
            contentIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
            PendingIntent piContent = PendingIntent.getActivity(this, 0, contentIntent,
                    PendingIntent.FLAG_UPDATE_CURRENT);

            Intent wifiSettingsIntent = new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK);
            PendingIntent piWifiSettings = PendingIntent.getActivity(this, 0, wifiSettingsIntent,
                    PendingIntent.FLAG_UPDATE_CURRENT);

            NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                    .setSmallIcon(R.mipmap.ic_launcher).setContentTitle("Network Error").setContentText(error)
                    .setStyle(new NotificationCompat.BigTextStyle().bigText(error))
                    .addAction(android.R.drawable.ic_menu_manage, "Wifi Settings", piWifiSettings)
                    .setContentIntent(piContent).setDefaults(Notification.DEFAULT_SOUND)
                    .setLights(Color.BLUE, 500, 1000);
            _notificationManager.notify(Config.PRESENCE_NOTIFICATION_ID, builder.build());
            Toast.makeText(this, error, Toast.LENGTH_LONG).show();
        }
    }

    // set logged in as false (because of network error)
    _ask.setLoggedIn(false);

    // store the presence update, will be triggered once network connection is reestablished
    _updateWaiting = true;
    _updateWaitingPresence = present;
    _updateWaitingLocation = location;
    _updateWaitingAdditionalInfo = additionalInfo;

    // just to make sure we don't get stuck
    _updatingPresence = false;
}

From source file:io.coldstart.android.GCMIntentService.java

private void SendCombinedNotification(String EventCount) {
    Notification notification = new Notification(R.drawable.ic_stat_alert, EventCount + " new SNMP Traps!",
            System.currentTimeMillis());
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notification.defaults |= Notification.DEFAULT_VIBRATE;
    notification.flags |= Notification.FLAG_SHOW_LIGHTS;

    notification.ledARGB = 0xffff0000;/*from   www.ja  va2 s  .  c om*/

    notification.ledOnMS = 300;
    notification.ledOffMS = 1000;

    notification.defaults |= Notification.DEFAULT_SOUND;

    Context context = getApplicationContext();
    Intent notificationIntent = new Intent(this, TrapListActivity.class);
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    notificationIntent.putExtra("forceRefresh", true);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
    notification.setLatestEventInfo(context, EventCount + " SNMP Traps", "Click to launch ColdStart.io",
            contentIntent);
    mNM.notify(43523, notification);//NotificationID++ 
}