Example usage for android.app Notification DEFAULT_VIBRATE

List of usage examples for android.app Notification DEFAULT_VIBRATE

Introduction

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

Prototype

int DEFAULT_VIBRATE

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

Click Source Link

Document

Use the default notification vibrate.

Usage

From source file:org.mariotaku.twidere.provider.TwidereDataProvider.java

private void buildNotification(final NotificationCompat.Builder builder, final String ticker,
        final String title, final String message, final int icon, final Bitmap large_icon,
        final Intent content_intent, final Intent delete_intent) {
    final Context context = getContext();
    builder.setTicker(ticker);/*from  w w w. java  2s  .  co m*/
    builder.setContentTitle(title);
    builder.setContentText(message);
    builder.setAutoCancel(true);
    builder.setWhen(System.currentTimeMillis());
    builder.setSmallIcon(icon);
    if (large_icon != null) {
        builder.setLargeIcon(large_icon);
    }
    if (delete_intent != null) {
        builder.setDeleteIntent(
                PendingIntent.getBroadcast(context, 0, delete_intent, PendingIntent.FLAG_UPDATE_CURRENT));
    }
    if (content_intent != null) {
        builder.setContentIntent(
                PendingIntent.getActivity(context, 0, content_intent, PendingIntent.FLAG_UPDATE_CURRENT));
    }
    int defaults = 0;
    final Calendar now = Calendar.getInstance();
    if (mNotificationIsAudible
            && !mPreferences.getBoolean("slient_notifications_at_" + now.get(Calendar.HOUR_OF_DAY), false)) {
        if (mPreferences.getBoolean(PREFERENCE_KEY_NOTIFICATION_HAVE_SOUND, false)) {
            builder.setSound(Uri.parse(mPreferences.getString(PREFERENCE_KEY_NOTIFICATION_RINGTONE,
                    Settings.System.DEFAULT_RINGTONE_URI.getPath())), Notification.STREAM_DEFAULT);
        }
        if (mPreferences.getBoolean(PREFERENCE_KEY_NOTIFICATION_HAVE_VIBRATION, false)) {
            defaults |= Notification.DEFAULT_VIBRATE;
        }
    }
    if (mPreferences.getBoolean(PREFERENCE_KEY_NOTIFICATION_HAVE_LIGHTS, false)) {
        final int color_def = context.getResources().getColor(R.color.holo_blue_dark);
        final int color = mPreferences.getInt(PREFERENCE_KEY_NOTIFICATION_LIGHT_COLOR, color_def);
        builder.setLights(color, 1000, 2000);
    }
    builder.setDefaults(defaults);
}

From source file:com.example.android.alertbuddy.BluetoothLeService.java

/**
 * This function will be used to update the notification as required. Note that this
 * function must be called explicitly by the class that does the detection.
 * The parameter value used to be the value (1, 2, 3, 4) that's be passed back by
 * the board. Depending on how we want to integrate the Detection algorithm with this,
 * this can be changed accordingly./*from w  w  w.  ja  v a 2 s .com*/
 * @param value
 */
protected void updateNotification(String value) {

    // set up icon if we want later
    mBuilder.setSmallIcon(R.drawable.ic_launcher);

    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, mIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(pendingIntent);

    // Set up builder
    mBuilder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher));
    mBuilder.setContentTitle("Environment Alert!");

    mBuilder.setContentText(value);

    // This part is for heads-up notification
    mBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
    mBuilder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher));
    mBuilder.setPriority(Notification.PRIORITY_HIGH);
    lockScreenNotification();

    // Put the finished builder to notificationManager
    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}

From source file:com.xabber.android.data.notification.NotificationManager.java

private void notify(int id, Notification notification) {
    LogManager.i(this,
            "Notification: " + id + ", ticker: " + notification.tickerText + ", sound: " + notification.sound
                    + ", vibro: " + (notification.defaults & Notification.DEFAULT_VIBRATE) + ", light: "
                    + (notification.defaults & Notification.DEFAULT_LIGHTS));
    try {//from w w  w . j  a  v  a 2s  .co  m
        notificationManager.notify(id, notification);
    } catch (SecurityException e) {
        LogManager.exception(this, e);
    }
}

From source file:com.lambdasoup.quickfit.alarm.AlarmService.java

@WorkerThread
private void refreshNotificationDisplay() {
    try (Cursor toNotify = getContentResolver().query(QuickFitContentProvider.getUriWorkoutsList(),
            new String[] { WorkoutEntry.SCHEDULE_ID, WorkoutEntry.WORKOUT_ID, WorkoutEntry.ACTIVITY_TYPE,
                    WorkoutEntry.LABEL, WorkoutEntry.DURATION_MINUTES },
            ScheduleEntry.TABLE_NAME + "." + ScheduleEntry.COL_SHOW_NOTIFICATION + "=?",
            new String[] { Integer.toString(ScheduleEntry.SHOW_NOTIFICATION_YES) }, null)) {
        int count = toNotify == null ? 0 : toNotify.getCount();
        if (count == 0) {
            Timber.d("refreshNotificationDisplay: no events");
            NotificationManager notificationManager = (NotificationManager) getSystemService(
                    NOTIFICATION_SERVICE);
            notificationManager.cancel(Constants.NOTIFICATION_ALARM);
            return;
        }// ww w.  j a  v  a 2  s.  c o m

        long[] scheduleIds = new long[count];
        int i = 0;
        toNotify.moveToPosition(-1);
        while (toNotify.moveToNext()) {
            scheduleIds[i] = toNotify.getLong(toNotify.getColumnIndex(WorkoutEntry.SCHEDULE_ID));
            i++;
        }

        PendingIntent cancelIntent = PendingIntent.getService(getApplicationContext(), 0,
                getIntentOnNotificationsCanceled(this, scheduleIds), PendingIntent.FLAG_UPDATE_CURRENT);

        NotificationCompat.Builder notification;
        if (count == 1) {
            Timber.d("refreshNotificationDisplay: single event");
            toNotify.moveToFirst();
            notification = notifySingleEvent(toNotify, cancelIntent);
        } else {
            Timber.d("refreshNotificationDisplay: multiple events");
            toNotify.moveToPosition(-1);
            notification = notifyMultipleEvents(toNotify, cancelIntent);
        }

        notification.setDeleteIntent(cancelIntent);
        notification.setAutoCancel(true);
        notification.setPriority(Notification.PRIORITY_HIGH);
        notification.setSmallIcon(R.drawable.ic_stat_quickfit_icon);
        notification.setColor(ContextCompat.getColor(this, R.color.colorPrimary));

        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
        String ringtoneUriStr = preferences.getString(getString(R.string.pref_key_notification_ringtone), null);
        if (ringtoneUriStr == null) {
            notification.setSound(
                    RingtoneManager.getActualDefaultRingtoneUri(this, RingtoneManager.TYPE_NOTIFICATION));
        } else if (!ringtoneUriStr.isEmpty()) {
            notification.setSound(Uri.parse(ringtoneUriStr));
        }
        boolean ledOn = preferences.getBoolean(getString(R.string.pref_key_notification_led), true);
        boolean vibrationOn = preferences.getBoolean(getString(R.string.pref_key_notification_vibrate), true);
        notification.setDefaults(
                (ledOn ? Notification.DEFAULT_LIGHTS : 0) | (vibrationOn ? Notification.DEFAULT_VIBRATE : 0));

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            notification.setCategory(Notification.CATEGORY_ALARM);
        }

        NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        notificationManager.notify(Constants.NOTIFICATION_ALARM, notification.build());
    }
}

From source file:at.jclehner.rxdroid.NotificationReceiver.java

public void updateNotification(Date date, int doseTime, boolean isActiveDoseTime, int mode) {
    final List<Drug> drugsWithLowSupplies = new ArrayList<Drug>();
    final int lowSupplyDrugCount = getDrugsWithLowSupplies(date, doseTime, drugsWithLowSupplies);
    final int missedDoseCount = getDrugsWithMissedDoses(date, doseTime, isActiveDoseTime, null);
    final int dueDoseCount = isActiveDoseTime ? getDrugsWithDueDoses(date, doseTime, null) : 0;

    int titleResId = R.string._title_notification_doses;
    int icon = R.drawable.ic_stat_normal;

    final StringBuilder sb = new StringBuilder();
    final String[] lines = new String[2];

    int lineCount = 0;

    if (missedDoseCount != 0 || dueDoseCount != 0) {
        if (dueDoseCount != 0)
            sb.append(RxDroid.getQuantityString(R.plurals._qmsg_due, dueDoseCount));

        if (missedDoseCount != 0) {
            if (sb.length() != 0)
                sb.append(", ");

            sb.append(RxDroid.getQuantityString(R.plurals._qmsg_missed, missedDoseCount));
        }//from w w  w. j a  va2s .  com

        lines[1] = "<b>" + getString(R.string._title_notification_doses) + "</b> "
                + Util.escapeHtml(sb.toString());
    }

    final boolean isShowingLowSupplyNotification;

    if (lowSupplyDrugCount != 0) {
        final String msg;
        final String first = drugsWithLowSupplies.get(0).getName();

        icon = R.drawable.ic_stat_exclamation;
        isShowingLowSupplyNotification = sb.length() == 0;
        //titleResId = R.string._title_notification_low_supplies;

        if (lowSupplyDrugCount == 1)
            msg = getString(R.string._qmsg_low_supply_single, first);
        else {
            final String second = drugsWithLowSupplies.get(1).getName();
            msg = RxDroid.getQuantityString(R.plurals._qmsg_low_supply_multiple, lowSupplyDrugCount - 1, first,
                    second);
        }

        if (isShowingLowSupplyNotification) {
            sb.append(msg);
            titleResId = R.string._title_notification_low_supplies;
        }

        lines[0] = "<b>" + getString(R.string._title_notification_low_supplies) + "</b> "
                + Util.escapeHtml(msg);
    } else
        isShowingLowSupplyNotification = false;

    final int priority;
    if (isShowingLowSupplyNotification)
        priority = NotificationCompat.PRIORITY_DEFAULT;
    else
        priority = NotificationCompat.PRIORITY_HIGH;

    final String message = sb.toString();
    final int currentHash = message.hashCode();
    final int lastHash = Settings.getInt(Settings.Keys.LAST_MSG_HASH);

    if (message.length() == 0) {
        getNotificationManager().cancel(R.id.notification);
        return;
    }

    final StringBuilder source = new StringBuilder();

    //      final InboxStyle inboxStyle = new InboxStyle();
    //      inboxStyle.setBigContentTitle(getString(R.string.app_name) +
    //            " (" + (dueDoseCount + missedDoseCount + lowSupplyDrugCount) + ")");

    for (String line : lines) {
        if (line != null) {
            if (lineCount != 0)
                source.append("\n<br/>\n");

            source.append(line);
            //            inboxStyle.addLine(Html.fromHtml(line));
            ++lineCount;
        }
    }

    final NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext);
    builder.setContentTitle(getString(titleResId));
    builder.setContentIntent(createDrugListIntent(date));
    builder.setContentText(message);
    builder.setTicker(getString(R.string._msg_new_notification));
    builder.setSmallIcon(icon);
    builder.setOngoing(true);
    builder.setUsesChronometer(false);
    builder.setWhen(0);
    builder.setPriority(priority);

    if (lineCount > 1) {
        final BigTextStyle style = new BigTextStyle();
        style.setBigContentTitle(getString(R.string.app_name));
        style.bigText(Html.fromHtml(source.toString()));
        builder.setStyle(style);
    }

    //      final long offset;
    //
    //      if(isActiveDoseTime)
    //         offset = Settings.getDoseTimeBeginOffset(doseTime);
    //      else
    //         offset = Settings.getTrueDoseTimeEndOffset(doseTime);
    //
    //      builder.setWhen(date.getTime() + offset);

    if (mode == NOTIFICATION_FORCE_UPDATE || currentHash != lastHash) {
        builder.setOnlyAlertOnce(false);
        Settings.putInt(Settings.Keys.LAST_MSG_HASH, currentHash);
    } else
        builder.setOnlyAlertOnce(true);

    // Prevents low supplies from constantly annoying the user with
    // notification's sound and/or vibration if alarms are repeated.
    if (isShowingLowSupplyNotification)
        mode = NOTIFICATION_FORCE_SILENT;

    int defaults = 0;

    final String lightColor = Settings.getString(Settings.Keys.NOTIFICATION_LIGHT_COLOR, "");
    if (lightColor.length() == 0)
        defaults |= Notification.DEFAULT_LIGHTS;
    else {
        try {
            int ledARGB = Integer.parseInt(lightColor, 16);
            if (ledARGB != 0) {
                ledARGB |= 0xff000000; // set alpha to ff
                builder.setLights(ledARGB, LED_ON_MS, LED_OFF_MS);
            }
        } catch (NumberFormatException e) {
            Log.e(TAG, "Failed to parse light color; using default", e);
            defaults |= Notification.DEFAULT_LIGHTS;
        }
    }

    if (mode != NOTIFICATION_FORCE_SILENT) {
        boolean isNowWithinQuietHours = false;

        do {
            if (!Settings.isChecked(Settings.Keys.QUIET_HOURS, false))
                break;

            final String quietHoursStr = Settings.getString(Settings.Keys.QUIET_HOURS);
            if (quietHoursStr == null)
                break;

            final TimePeriod quietHours = TimePeriod.fromString(quietHoursStr);
            if (quietHours.contains(DumbTime.now()))
                isNowWithinQuietHours = true;

        } while (false);

        if (!isNowWithinQuietHours) {
            final String ringtone = Settings.getString(Settings.Keys.NOTIFICATION_SOUND);
            if (ringtone != null)
                builder.setSound(Uri.parse(ringtone));
            else
                defaults |= Notification.DEFAULT_SOUND;

            if (LOGV)
                Log.i(TAG, "Sound: " + (ringtone != null ? ringtone.toString() : "(default)"));
        } else
            Log.i(TAG, "Currently within quiet hours; muting sound...");
    }

    if (mode != NOTIFICATION_FORCE_SILENT && Settings.getBoolean(Settings.Keys.USE_VIBRATOR, true))
        defaults |= Notification.DEFAULT_VIBRATE;

    builder.setDefaults(defaults);

    getNotificationManager().notify(R.id.notification, builder.build());
}

From source file:com.socialdisasters.other.service.ChatService.java

@SuppressWarnings("deprecation")
private void showNotification(Intent intent) {
    int defaults = 0;

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    if (prefs.getBoolean("vibrateOnMessage", true)) {
        defaults |= Notification.DEFAULT_VIBRATE;
    }// w ww  .  ja va 2s .c  om

    Long buddyId = intent.getLongExtra(EXTRA_BUDDY_ID, -1L);
    String displayName = intent.getStringExtra(EXTRA_DISPLAY_NAME);
    String textBody = intent.getStringExtra(EXTRA_TEXT_BODY);

    CharSequence tickerText = getString(R.string.new_message_from) + " " + displayName;
    CharSequence contentTitle = getString(R.string.new_message);
    CharSequence contentText = displayName + ":\n" + textBody;

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);

    // forward intent to the activity
    intent.setClass(this, MainActivity.class);

    // Adds the intent to the main view
    stackBuilder.addNextIntent(intent);

    // Gets a PendingIntent containing the entire back stack
    PendingIntent contentIntent = stackBuilder.getPendingIntent(buddyId.intValue(),
            PendingIntent.FLAG_UPDATE_CURRENT);

    // create a reply intent
    String replyLabel = getResources().getString(R.string.reply_label);
    RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY).setLabel(replyLabel).build();

    Intent replyIntent = new Intent(this, ReplyActivity.class);
    replyIntent.putExtra(EXTRA_BUDDY_ID, buddyId);
    PendingIntent replyPendingIntent = PendingIntent.getActivity(this, buddyId.intValue(), replyIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Action action = new NotificationCompat.Action.Builder(R.drawable.ic_action_reply,
            getString(R.string.reply_label), replyPendingIntent).addRemoteInput(remoteInput).build();

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder.setContentTitle(contentTitle);
    builder.setContentText(contentText);
    builder.setSmallIcon(R.drawable.ic_stat_message);
    builder.setTicker(tickerText);
    builder.setDefaults(defaults);
    builder.setWhen(System.currentTimeMillis());
    builder.setContentIntent(contentIntent);
    builder.setLights(0xffff0000, 300, 1000);
    builder.setSound(
            Uri.parse(prefs.getString("ringtoneOnMessage", "content://settings/system/notification_sound")));
    builder.extend(new WearableExtender().addAction(action));
    builder.setAutoCancel(false);

    Notification notification = builder.getNotification();

    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(buddyId.toString(), MESSAGE_NOTIFICATION, notification);

    if (prefs.getBoolean("ttsWhenOnHeadset", false)) {
        AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);

        if (am.isBluetoothA2dpOn() || am.isWiredHeadsetOn()) {
            // speak the notification
            Intent tts_intent = new Intent(this, TTSService.class);
            tts_intent.setAction(TTSService.INTENT_SPEAK);
            tts_intent.putExtra("speechText", tickerText + ": " + textBody);
            startService(tts_intent);
        }
    }
}

From source file:com.android.email.EmailNotificationController.java

/** Sets up the notification's sound and vibration based upon account details. */
private void setupSoundAndVibration(NotificationCompat.Builder builder, Account account) {
    String ringtoneUri = Settings.System.DEFAULT_NOTIFICATION_URI.toString();
    boolean vibrate = false;

    // Use the Inbox notification preferences
    final Cursor accountCursor = mContext.getContentResolver().query(
            EmailProvider.uiUri("uiaccount", account.mId), UIProvider.ACCOUNTS_PROJECTION, null, null, null);

    com.android.mail.providers.Account uiAccount = null;
    try {/*  w w  w  .  ja  v a  2s.c om*/
        if (accountCursor.moveToFirst()) {
            uiAccount = com.android.mail.providers.Account.builder().buildFrom(accountCursor);
        }
    } finally {
        accountCursor.close();
    }

    if (uiAccount != null) {
        final Cursor folderCursor = mContext.getContentResolver().query(uiAccount.settings.defaultInbox,
                UIProvider.FOLDERS_PROJECTION, null, null, null);

        if (folderCursor == null) {
            // This can happen when the notification is for the security policy notification
            // that happens before the account is setup
            LogUtils.w(LOG_TAG, "Null folder cursor for mailbox %s", uiAccount.settings.defaultInbox);
        } else {
            Folder folder = null;
            try {
                if (folderCursor.moveToFirst()) {
                    folder = new Folder(folderCursor);
                }
            } finally {
                folderCursor.close();
            }

            if (folder != null) {
                final FolderPreferences folderPreferences = new FolderPreferences(mContext,
                        uiAccount.getEmailAddress(), folder, true /* inbox */);

                ringtoneUri = folderPreferences.getNotificationRingtoneUri();
                vibrate = folderPreferences.isNotificationVibrateEnabled();
            } else {
                LogUtils.e(LOG_TAG, "Null folder for mailbox %s", uiAccount.settings.defaultInbox);
            }
        }
    } else {
        LogUtils.e(LOG_TAG, "Null uiAccount for account id %d", account.mId);
    }

    int defaults = Notification.DEFAULT_LIGHTS;
    if (vibrate) {
        defaults |= Notification.DEFAULT_VIBRATE;
    }

    builder.setSound(TextUtils.isEmpty(ringtoneUri) ? null : Uri.parse(ringtoneUri)).setDefaults(defaults);
}

From source file:com.indeema.email.NotificationController.java

/** Sets up the notification's sound and vibration based upon account details. */
private void setupSoundAndVibration(NotificationCompat.Builder builder, Account account) {
    String ringtoneUri = Settings.System.DEFAULT_NOTIFICATION_URI.toString();
    boolean vibrate = false;

    // Use the Inbox notification preferences
    final Cursor accountCursor = mContext.getContentResolver().query(
            EmailProvider.uiUri("uiaccount", account.mId), UIProvider.ACCOUNTS_PROJECTION, null, null, null);

    com.indeema.mail.providers.Account uiAccount = null;
    try {/*from  w  w  w  .j  a va2 s .  co  m*/
        if (accountCursor.moveToFirst()) {
            uiAccount = new com.indeema.mail.providers.Account(accountCursor);
        }
    } finally {
        accountCursor.close();
    }

    if (uiAccount != null) {
        final Cursor folderCursor = mContext.getContentResolver().query(uiAccount.settings.defaultInbox,
                UIProvider.FOLDERS_PROJECTION, null, null, null);

        if (folderCursor == null) {
            // This can happen when the notification is for the security policy notification
            // that happens before the account is setup
            LogUtils.w(LOG_TAG, "Null folder cursor for mailbox %s", uiAccount.settings.defaultInbox);
        } else {
            Folder folder = null;
            try {
                if (folderCursor.moveToFirst()) {
                    folder = new Folder(folderCursor);
                }
            } finally {
                folderCursor.close();
            }

            if (folder != null) {
                final FolderPreferences folderPreferences = new FolderPreferences(mContext,
                        uiAccount.getEmailAddress(), folder, true /* inbox */);

                ringtoneUri = folderPreferences.getNotificationRingtoneUri();
                vibrate = folderPreferences.isNotificationVibrateEnabled();
            } else {
                LogUtils.e(LOG_TAG, "Null folder for mailbox %s", uiAccount.settings.defaultInbox);
            }
        }
    } else {
        LogUtils.e(LOG_TAG, "Null uiAccount for account id %d", account.mId);
    }

    int defaults = Notification.DEFAULT_LIGHTS;
    if (vibrate) {
        defaults |= Notification.DEFAULT_VIBRATE;
    }

    builder.setSound(TextUtils.isEmpty(ringtoneUri) ? null : Uri.parse(ringtoneUri)).setDefaults(defaults);
}

From source file:com.android.email.NotificationController.java

/** Sets up the notification's sound and vibration based upon account details. */
private void setupSoundAndVibration(NotificationCompat.Builder builder, Account account) {
    String ringtoneUri = Settings.System.DEFAULT_NOTIFICATION_URI.toString();
    boolean vibrate = false;

    // Use the Inbox notification preferences
    final Cursor accountCursor = mContext.getContentResolver().query(
            EmailProvider.uiUri("uiaccount", account.mId), UIProvider.ACCOUNTS_PROJECTION, null, null, null);

    com.android.mail.providers.Account uiAccount = null;
    try {// ww  w . j ava  2s  .co  m
        if (accountCursor.moveToFirst()) {
            uiAccount = new com.android.mail.providers.Account(accountCursor);
        }
    } finally {
        accountCursor.close();
    }

    if (uiAccount != null) {
        final Cursor folderCursor = mContext.getContentResolver().query(uiAccount.settings.defaultInbox,
                UIProvider.FOLDERS_PROJECTION, null, null, null);

        if (folderCursor == null) {
            // This can happen when the notification is for the security policy notification
            // that happens before the account is setup
            LogUtils.w(LOG_TAG, "Null folder cursor for mailbox %s", uiAccount.settings.defaultInbox);
        } else {
            Folder folder = null;
            try {
                if (folderCursor.moveToFirst()) {
                    folder = new Folder(folderCursor);
                }
            } finally {
                folderCursor.close();
            }

            if (folder != null) {
                final FolderPreferences folderPreferences = new FolderPreferences(mContext,
                        uiAccount.getEmailAddress(), folder, true /* inbox */);

                ringtoneUri = folderPreferences.getNotificationRingtoneUri();
                vibrate = folderPreferences.isNotificationVibrateEnabled();
            } else {
                LogUtils.e(LOG_TAG, "Null folder for mailbox %s", uiAccount.settings.defaultInbox);
            }
        }
    } else {
        LogUtils.e(LOG_TAG, "Null uiAccount for account id %d", account.mId);
    }

    int defaults = Notification.DEFAULT_LIGHTS;
    if (vibrate) {
        defaults |= Notification.DEFAULT_VIBRATE;
    }

    builder.setSound(TextUtils.isEmpty(ringtoneUri) ? null : Uri.parse(ringtoneUri)).setDefaults(defaults);
}

From source file:com.wondertoys.pokevalue.utils.AutoUpdateApk.java

protected void raise_notification() {
    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager nm = (NotificationManager) context.getSystemService(ns);

    String update_file = preferences.getString(UPDATE_FILE, "");
    if (update_file.length() > 0) {
        setChanged();/*from  ww w  . j a  va  2 s . c o m*/
        notifyObservers(AUTOUPDATE_HAVE_UPDATE);

        // raise the notification
        CharSequence contentTitle = appName + " update available";
        CharSequence contentText = "Select to install";
        Intent notificationIntent = new Intent(Intent.ACTION_VIEW);
        notificationIntent.setDataAndType(Uri.parse(
                "file://" + Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/"
                        + update_file),
                ANDROID_PACKAGE);
        PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
        builder.setDefaults(
                Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE);
        builder.setSmallIcon(appIcon);
        builder.setTicker(appName + " update");
        builder.setContentTitle(contentTitle);
        builder.setContentText(contentText);
        builder.setContentIntent(contentIntent);
        builder.setWhen(System.currentTimeMillis());
        builder.setAutoCancel(true);
        builder.setOngoing(true);

        nm.notify(NOTIFICATION_ID, builder.build());
    } else {
        //nm.cancel( NOTIFICATION_ID );   // tried this, but it just doesn't do the trick =(
        nm.cancelAll();
    }
}