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:com.mattprecious.notisync.service.SecondaryService.java

private void handlePhoneCallMessage(PhoneCallMessage message) {
    if (!Preferences.getSecondaryPhoneCallEnabled(this)) {
        return;//from  ww  w .ja  va2 s  . co m
    }

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder.setSound(getRingtoneUri(Preferences.getSecondaryPhoneCallRingtone(this)));
    builder.setAutoCancel(true);

    int defaults = 0;
    if (Preferences.getSecondaryPhoneCallVibrate(this)) {
        defaults |= Notification.DEFAULT_VIBRATE;
    }

    if (Preferences.getSecondaryPhoneCallLights(this)) {
        defaults |= Notification.DEFAULT_LIGHTS;
    }

    builder.setDefaults(defaults);

    PendingIntent intent = PendingIntent.getActivity(this, 0, new Intent(), 0);
    builder.setContentIntent(intent);

    int notificationId;
    if (message.type == PhoneCallMessage.Type.INCOMING) {
        incomingCallMessage = message;

        notificationId = NOTIFICATION_ID_PHONE_INCOMING;
        builder.setContentTitle(getString(R.string.noti_title_incoming_call));
        builder.setSmallIcon(R.drawable.ic_stat_incoming);
    } else if (message.type == PhoneCallMessage.Type.MISSED) {
        notificationId = NOTIFICATION_ID_PHONE_MISSED;
        builder.setContentTitle(getString(R.string.noti_title_missed_call));
        builder.setSmallIcon(R.drawable.ic_stat_missed_call);

        if (incomingCallMessage != null && message.number != null
                && message.number.equals(incomingCallMessage.number)) {
            notificationManager.cancel(NOTIFICATION_ID_PHONE_INCOMING);
            incomingCallMessage = null;
        }
    } else {
        return;
    }

    String text;
    if (message.name != null) {
        text = message.name;
    } else {
        text = PhoneNumberUtils.formatNumber(message.number);
    }

    builder.setContentText(text);

    Notification notification = builder.build();
    notificationManager.notify(notificationId, notification);

    openNotificationDatabaseWrite();
    notificationsDbAdapter.insertNotification("phone.call", "phone", "Phone call", text,
            PhoneNumberUtils.formatNumber(message.number), System.currentTimeMillis() + "");
    notificationsDbAdapter.close();
}

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;// ww w  .j  a va 2 s .c  o m

    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++ 
}

From source file:com.chen.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.chen.mail.providers.Account uiAccount = null;
    try {//from w w w .j  a  va2 s. c  om
        if (accountCursor.moveToFirst()) {
            uiAccount = new com.chen.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.google.samples.apps.sergio.service.SessionAlarmService.java

private void notifySessionFeedback(boolean debug) {
    LOGD(TAG, "Considering firing notification for session feedback.");

    if (debug) {//from   w  w  w .  j  a va 2 s .c o m
        LOGD(TAG, "Note: this is a debug notification.");
    }

    // Don't fire notification if this feature is disabled in settings
    if (!PrefUtils.shouldShowSessionFeedbackReminders(this)) {
        LOGD(TAG, "Skipping session feedback notification. Disabled in settings.");
        return;
    }

    final Cursor c = getContentResolver().query(ScheduleContract.Sessions.CONTENT_MY_SCHEDULE_URI,
            SessionsNeedingFeedbackQuery.PROJECTION, SessionsNeedingFeedbackQuery.WHERE_CLAUSE, null, null);
    if (c == null) {
        return;
    }

    List<String> needFeedbackIds = new ArrayList<String>();
    List<String> needFeedbackTitles = new ArrayList<String>();
    while (c.moveToNext()) {
        String sessionId = c.getString(SessionsNeedingFeedbackQuery.SESSION_ID);
        String sessionTitle = c.getString(SessionsNeedingFeedbackQuery.SESSION_TITLE);

        // Avoid repeated notifications.
        if (UIUtils.isFeedbackNotificationFiredForSession(this, sessionId)) {
            LOGD(TAG, "Skipping repeated session feedback notification for session '" + sessionTitle + "'");
            continue;
        }

        needFeedbackIds.add(sessionId);
        needFeedbackTitles.add(sessionTitle);
    }

    if (needFeedbackIds.size() == 0) {
        // the user has already been notified of all sessions needing feedback
        return;
    }

    LOGD(TAG,
            "Going forward with session feedback notification for " + needFeedbackIds.size() + " session(s).");

    final Resources res = getResources();

    // this is used to synchronize deletion of notifications on phone and wear
    Intent dismissalIntent = new Intent(ACTION_NOTIFICATION_DISMISSAL);
    // TODO: fix Wear dismiss integration
    //dismissalIntent.putExtra(KEY_SESSION_ID, sessionId);
    PendingIntent dismissalPendingIntent = PendingIntent.getService(this, (int) new Date().getTime(),
            dismissalIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    String provideFeedbackTicker = res.getString(R.string.session_feedback_notification_ticker);
    NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(this)
            .setColor(getResources().getColor(R.color.theme_primary)).setContentText(provideFeedbackTicker)
            .setTicker(provideFeedbackTicker)
            .setLights(SessionAlarmService.NOTIFICATION_ARGB_COLOR, SessionAlarmService.NOTIFICATION_LED_ON_MS,
                    SessionAlarmService.NOTIFICATION_LED_OFF_MS)
            .setSmallIcon(R.drawable.ic_stat_notification).setPriority(Notification.PRIORITY_LOW)
            .setLocalOnly(true) // make it local to the phone
            .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE)
            .setDeleteIntent(dismissalPendingIntent).setAutoCancel(true);

    if (needFeedbackIds.size() == 1) {
        // Only 1 session needs feedback
        Uri sessionUri = ScheduleContract.Sessions.buildSessionUri(needFeedbackIds.get(0));
        PendingIntent pi = TaskStackBuilder.create(this)
                .addNextIntent(new Intent(this, MyScheduleActivity.class))
                .addNextIntent(new Intent(Intent.ACTION_VIEW, sessionUri, this, SessionFeedbackActivity.class))
                .getPendingIntent(1, PendingIntent.FLAG_CANCEL_CURRENT);

        notifBuilder.setContentTitle(needFeedbackTitles.get(0)).setContentIntent(pi);
    } else {
        // Show information about several sessions that need feedback
        PendingIntent pi = TaskStackBuilder.create(this)
                .addNextIntent(new Intent(this, MyScheduleActivity.class))
                .getPendingIntent(1, PendingIntent.FLAG_CANCEL_CURRENT);

        NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
        inboxStyle.setBigContentTitle(provideFeedbackTicker);
        for (String title : needFeedbackTitles) {
            inboxStyle.addLine(title);
        }

        notifBuilder
                .setContentTitle(getResources().getQuantityString(R.plurals.session_plurals,
                        needFeedbackIds.size(), needFeedbackIds.size()))
                .setStyle(inboxStyle).setContentIntent(pi);
    }

    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    LOGD(TAG, "Now showing session feedback notification!");
    nm.notify(FEEDBACK_NOTIFICATION_ID, notifBuilder.build());

    for (int i = 0; i < needFeedbackIds.size(); i++) {
        setupNotificationOnWear(needFeedbackIds.get(i), null, needFeedbackTitles.get(i), null);
    }
}

From source file:com.jjcamera.apps.iosched.service.SessionAlarmService.java

/**
 *  A starred session is about to end. Notify the user to provide session feedback.
 *  Constructs and triggers a system notification. Does nothing if the session has already
 *  concluded.//from  w w  w  .jav  a 2s .c o  m
 */
private void notifySessionFeedback(boolean debug) {
    LOGD(TAG, "Considering firing notification for session feedback.");

    if (debug) {
        LOGW(TAG, "Note: this is a debug notification.");
    }

    // Don't fire notification if this feature is disabled in settings
    if (!SettingsUtils.shouldShowSessionFeedbackReminders(this)) {
        LOGD(TAG, "Skipping session feedback notification. Disabled in settings.");
        return;
    }

    Cursor c = null;
    try {
        c = getContentResolver().query(ScheduleContract.Sessions.CONTENT_MY_SCHEDULE_URI,
                SessionsNeedingFeedbackQuery.PROJECTION, SessionsNeedingFeedbackQuery.WHERE_CLAUSE, null, null);
        if (c == null) {
            return;
        }

        FeedbackHelper feedbackHelper = new FeedbackHelper(this);

        List<String> needFeedbackIds = new ArrayList<String>();
        List<String> needFeedbackTitles = new ArrayList<String>();
        while (c.moveToNext()) {
            String sessionId = c.getString(SessionsNeedingFeedbackQuery.SESSION_ID);
            String sessionTitle = c.getString(SessionsNeedingFeedbackQuery.SESSION_TITLE);

            // Avoid repeated notifications.
            if (feedbackHelper.isFeedbackNotificationFiredForSession(sessionId)) {
                LOGD(TAG, "Skipping repeated session feedback notification for session '" + sessionTitle + "'");
                continue;
            }

            needFeedbackIds.add(sessionId);
            needFeedbackTitles.add(sessionTitle);
        }

        if (needFeedbackIds.size() == 0) {
            // the user has already been notified of all sessions needing feedback
            return;
        }

        LOGD(TAG, "Going forward with session feedback notification for " + needFeedbackIds.size()
                + " session(s).");

        final Resources res = getResources();

        // this is used to synchronize deletion of notifications on phone and wear
        Intent dismissalIntent = new Intent(ACTION_NOTIFICATION_DISMISSAL);
        // TODO: fix Wear dismiss integration
        //dismissalIntent.putExtra(KEY_SESSION_ID, sessionId);
        PendingIntent dismissalPendingIntent = PendingIntent.getService(this, (int) new Date().getTime(),
                dismissalIntent, PendingIntent.FLAG_UPDATE_CURRENT);

        String provideFeedbackTicker = res.getString(R.string.session_feedback_notification_ticker);
        NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(this)
                .setColor(getResources().getColor(R.color.theme_primary)).setContentText(provideFeedbackTicker)
                .setTicker(provideFeedbackTicker)
                .setLights(SessionAlarmService.NOTIFICATION_ARGB_COLOR,
                        SessionAlarmService.NOTIFICATION_LED_ON_MS, SessionAlarmService.NOTIFICATION_LED_OFF_MS)
                .setSmallIcon(R.drawable.ic_stat_notification).setPriority(Notification.PRIORITY_LOW)
                .setLocalOnly(true) // make it local to the phone
                .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE)
                .setDeleteIntent(dismissalPendingIntent).setAutoCancel(true);

        if (needFeedbackIds.size() == 1) {
            // Only 1 session needs feedback
            Uri sessionUri = ScheduleContract.Sessions.buildSessionUri(needFeedbackIds.get(0));
            PendingIntent pi = TaskStackBuilder.create(this)
                    .addNextIntent(new Intent(this, MyScheduleActivity.class))
                    .addNextIntent(
                            new Intent(Intent.ACTION_VIEW, sessionUri, this, SessionFeedbackActivity.class))
                    .getPendingIntent(1, PendingIntent.FLAG_CANCEL_CURRENT);

            notifBuilder.setContentTitle(needFeedbackTitles.get(0)).setContentIntent(pi);
        } else {
            // Show information about several sessions that need feedback
            PendingIntent pi = TaskStackBuilder.create(this)
                    .addNextIntent(new Intent(this, MyScheduleActivity.class))
                    .getPendingIntent(1, PendingIntent.FLAG_CANCEL_CURRENT);

            NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
            inboxStyle.setBigContentTitle(provideFeedbackTicker);
            for (String title : needFeedbackTitles) {
                inboxStyle.addLine(title);
            }

            notifBuilder
                    .setContentTitle(getResources().getQuantityString(R.plurals.session_plurals,
                            needFeedbackIds.size(), needFeedbackIds.size()))
                    .setStyle(inboxStyle).setContentIntent(pi);
        }

        NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        LOGD(TAG, "Now showing session feedback notification!");
        nm.notify(FEEDBACK_NOTIFICATION_ID, notifBuilder.build());

        /*for (int i = 0; i < needFeedbackIds.size(); i++) {
        setupNotificationOnWear(needFeedbackIds.get(i), null, needFeedbackTitles.get(i), null);
        feedbackHelper.setFeedbackNotificationAsFiredForSession(needFeedbackIds.get(i));
        }*/
    } finally {
        if (c != null) {
            try {
                c.close();
            } catch (Exception ignored) {
            }
        }
    }
}

From source file:com.google.samples.apps.iosched.service.SessionAlarmService.java

/**
 *  A starred session is about to end. Notify the user to provide session feedback.
 *  Constructs and triggers a system notification. Does nothing if the session has already
 *  concluded.//from  www .  j  a va 2  s. co m
 */
private void notifySessionFeedback(boolean debug) {
    LOGD(TAG, "Considering firing notification for session feedback.");

    if (debug) {
        LOGW(TAG, "Note: this is a debug notification.");
    }

    // Don't fire notification if this feature is disabled in settings
    if (!SettingsUtils.shouldShowSessionFeedbackReminders(this)) {
        LOGD(TAG, "Skipping session feedback notification. Disabled in settings.");
        return;
    }

    Cursor c = null;
    try {
        c = getContentResolver().query(ScheduleContract.Sessions.CONTENT_MY_SCHEDULE_URI,
                SessionsNeedingFeedbackQuery.PROJECTION, SessionsNeedingFeedbackQuery.WHERE_CLAUSE, null, null);
        if (c == null) {
            return;
        }

        FeedbackHelper feedbackHelper = new FeedbackHelper(this);

        List<String> needFeedbackIds = new ArrayList<String>();
        List<String> needFeedbackTitles = new ArrayList<String>();
        while (c.moveToNext()) {
            String sessionId = c.getString(SessionsNeedingFeedbackQuery.SESSION_ID);
            String sessionTitle = c.getString(SessionsNeedingFeedbackQuery.SESSION_TITLE);

            // Avoid repeated notifications.
            if (feedbackHelper.isFeedbackNotificationFiredForSession(sessionId)) {
                LOGD(TAG, "Skipping repeated session feedback notification for session '" + sessionTitle + "'");
                continue;
            }

            needFeedbackIds.add(sessionId);
            needFeedbackTitles.add(sessionTitle);
        }

        if (needFeedbackIds.size() == 0) {
            // the user has already been notified of all sessions needing feedback
            return;
        }

        LOGD(TAG, "Going forward with session feedback notification for " + needFeedbackIds.size()
                + " session(s).");

        final Resources res = getResources();

        // this is used to synchronize deletion of notifications on phone and wear
        Intent dismissalIntent = new Intent(ACTION_NOTIFICATION_DISMISSAL);
        // TODO: fix Wear dismiss integration
        //dismissalIntent.putExtra(KEY_SESSION_ID, sessionId);
        PendingIntent dismissalPendingIntent = PendingIntent.getService(this, (int) new Date().getTime(),
                dismissalIntent, PendingIntent.FLAG_UPDATE_CURRENT);

        String provideFeedbackTicker = res.getString(R.string.session_feedback_notification_ticker);
        NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(this)
                .setColor(getResources().getColor(R.color.theme_primary)).setContentText(provideFeedbackTicker)
                .setTicker(provideFeedbackTicker)
                .setLights(SessionAlarmService.NOTIFICATION_ARGB_COLOR,
                        SessionAlarmService.NOTIFICATION_LED_ON_MS, SessionAlarmService.NOTIFICATION_LED_OFF_MS)
                .setSmallIcon(R.drawable.ic_stat_notification).setPriority(Notification.PRIORITY_LOW)
                .setLocalOnly(true) // make it local to the phone
                .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE)
                .setDeleteIntent(dismissalPendingIntent).setAutoCancel(true);

        if (needFeedbackIds.size() == 1) {
            // Only 1 session needs feedback
            Uri sessionUri = ScheduleContract.Sessions.buildSessionUri(needFeedbackIds.get(0));
            PendingIntent pi = TaskStackBuilder.create(this)
                    .addNextIntent(new Intent(this, MyScheduleActivity.class))
                    .addNextIntent(
                            new Intent(Intent.ACTION_VIEW, sessionUri, this, SessionFeedbackActivity.class))
                    .getPendingIntent(1, PendingIntent.FLAG_CANCEL_CURRENT);

            notifBuilder.setContentTitle(needFeedbackTitles.get(0)).setContentIntent(pi);
        } else {
            // Show information about several sessions that need feedback
            PendingIntent pi = TaskStackBuilder.create(this)
                    .addNextIntent(new Intent(this, MyScheduleActivity.class))
                    .getPendingIntent(1, PendingIntent.FLAG_CANCEL_CURRENT);

            NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
            inboxStyle.setBigContentTitle(provideFeedbackTicker);
            for (String title : needFeedbackTitles) {
                inboxStyle.addLine(title);
            }

            notifBuilder
                    .setContentTitle(getResources().getQuantityString(R.plurals.session_plurals,
                            needFeedbackIds.size(), needFeedbackIds.size()))
                    .setStyle(inboxStyle).setContentIntent(pi);
        }

        NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        LOGD(TAG, "Now showing session feedback notification!");
        nm.notify(FEEDBACK_NOTIFICATION_ID, notifBuilder.build());

        for (int i = 0; i < needFeedbackIds.size(); i++) {
            setupNotificationOnWear(needFeedbackIds.get(i), null, needFeedbackTitles.get(i), null);
            feedbackHelper.setFeedbackNotificationAsFiredForSession(needFeedbackIds.get(i));
        }
    } finally {
        if (c != null) {
            try {
                c.close();
            } catch (Exception ignored) {
            }
        }
    }
}

From source file:com.nbplus.vbroadlistener.gcm.MyGcmListenerService.java

private void showNotification(Context context, int notificationId, int smallIconId, String title,
        String contentText, String bigTitle, String bigContentText, String summaryText, String ticker,
        Intent intent) {/* w w w.  jav a2  s.c o  m*/
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    builder.setSound(soundUri);

    if (smallIconId == 0) {
        builder.setSmallIcon(R.mipmap.ic_launcher);
    } else {
        builder.setSmallIcon(smallIconId);
    }
    builder.setWhen(System.currentTimeMillis());
    //builder.setNumber(10);

    if (!StringUtils.isEmptyString(ticker)) {
        builder.setTicker(ticker);
    }

    if (StringUtils.isEmptyString(title)) {
        builder.setContentTitle(PackageUtils.getApplicationName(context));
    } else {
        builder.setContentTitle(title);
    }
    builder.setContentText(contentText);
    builder.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE);
    builder.setAutoCancel(true);

    // big title and text
    if (!StringUtils.isEmptyString(bigTitle) && !StringUtils.isEmptyString(bigContentText)) {
        NotificationCompat.BigTextStyle style = new NotificationCompat.BigTextStyle(builder);
        if (!StringUtils.isEmptyString(summaryText)) {
            style.setSummaryText(summaryText);
        }
        style.setBigContentTitle(bigTitle);
        style.bigText(bigContentText);

        builder.setStyle(style);
    }

    if (intent != null) {
        intent.setFlags(intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP
                | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, notificationId, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        builder.setContentIntent(pendingIntent);
    }

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

From source file:com.saarang.samples.apps.iosched.service.SessionAlarmService.java

private void notifySessionFeedback(boolean debug) {
    LogUtils.LOGD(TAG, "Considering firing notification for session feedback.");

    if (debug) {//from  w  w w  .  j a v  a  2 s.  co  m
        LogUtils.LOGD(TAG, "Note: this is a debug notification.");
    }

    // Don't fire notification if this feature is disabled in settings
    if (!PrefUtils.shouldShowSessionFeedbackReminders(this)) {
        LogUtils.LOGD(TAG, "Skipping session feedback notification. Disabled in settings.");
        return;
    }

    final Cursor c = getContentResolver().query(ScheduleContract.Sessions.CONTENT_MY_SCHEDULE_URI,
            SessionsNeedingFeedbackQuery.PROJECTION, SessionsNeedingFeedbackQuery.WHERE_CLAUSE, null, null);
    if (c == null) {
        return;
    }

    List<String> needFeedbackIds = new ArrayList<String>();
    List<String> needFeedbackTitles = new ArrayList<String>();
    while (c.moveToNext()) {
        String sessionId = c.getString(SessionsNeedingFeedbackQuery.SESSION_ID);
        String sessionTitle = c.getString(SessionsNeedingFeedbackQuery.SESSION_TITLE);

        // Avoid repeated notifications.
        if (UIUtils.isFeedbackNotificationFiredForSession(this, sessionId)) {
            LogUtils.LOGD(TAG,
                    "Skipping repeated session feedback notification for session '" + sessionTitle + "'");
            continue;
        }

        needFeedbackIds.add(sessionId);
        needFeedbackTitles.add(sessionTitle);
    }

    if (needFeedbackIds.size() == 0) {
        // the user has already been notified of all sessions needing feedback
        return;
    }

    LogUtils.LOGD(TAG,
            "Going forward with session feedback notification for " + needFeedbackIds.size() + " session(s).");

    final Resources res = getResources();

    // this is used to synchronize deletion of notifications on phone and wear
    Intent dismissalIntent = new Intent(ACTION_NOTIFICATION_DISMISSAL);
    // TODO: fix Wear dismiss integration
    //dismissalIntent.putExtra(KEY_SESSION_ID, sessionId);
    PendingIntent dismissalPendingIntent = PendingIntent.getService(this, (int) new Date().getTime(),
            dismissalIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    String provideFeedbackTicker = res
            .getString(com.saarang.samples.apps.iosched.R.string.session_feedback_notification_ticker);
    NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(this)
            .setColor(getResources().getColor(com.saarang.samples.apps.iosched.R.color.theme_primary))
            .setContentText(provideFeedbackTicker).setTicker(provideFeedbackTicker)
            .setLights(SessionAlarmService.NOTIFICATION_ARGB_COLOR, SessionAlarmService.NOTIFICATION_LED_ON_MS,
                    SessionAlarmService.NOTIFICATION_LED_OFF_MS)
            .setSmallIcon(com.saarang.samples.apps.iosched.R.drawable.ic_stat_notification)
            .setPriority(Notification.PRIORITY_LOW).setLocalOnly(true) // make it local to the phone
            .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE)
            .setDeleteIntent(dismissalPendingIntent).setAutoCancel(true);

    if (needFeedbackIds.size() == 1) {
        // Only 1 session needs feedback
        Uri sessionUri = ScheduleContract.Sessions.buildSessionUri(needFeedbackIds.get(0));
        PendingIntent pi = TaskStackBuilder.create(this)
                .addNextIntent(new Intent(this, MyScheduleActivity.class))
                .addNextIntent(new Intent(Intent.ACTION_VIEW, sessionUri, this, SessionFeedbackActivity.class))
                .getPendingIntent(1, PendingIntent.FLAG_CANCEL_CURRENT);

        notifBuilder.setContentTitle(needFeedbackTitles.get(0)).setContentIntent(pi);
    } else {
        // Show information about several sessions that need feedback
        PendingIntent pi = TaskStackBuilder.create(this)
                .addNextIntent(new Intent(this, MyScheduleActivity.class))
                .getPendingIntent(1, PendingIntent.FLAG_CANCEL_CURRENT);

        NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
        inboxStyle.setBigContentTitle(provideFeedbackTicker);
        for (String title : needFeedbackTitles) {
            inboxStyle.addLine(title);
        }

        notifBuilder.setContentTitle(
                getResources().getQuantityString(com.saarang.samples.apps.iosched.R.plurals.session_plurals,
                        needFeedbackIds.size(), needFeedbackIds.size()))
                .setStyle(inboxStyle).setContentIntent(pi);
    }

    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    LogUtils.LOGD(TAG, "Now showing session feedback notification!");
    nm.notify(FEEDBACK_NOTIFICATION_ID, notifBuilder.build());

    for (int i = 0; i < needFeedbackIds.size(); i++) {
        setupNotificationOnWear(needFeedbackIds.get(i), null, needFeedbackTitles.get(i), null);
    }
}

From source file:org.linphone.compatibility.ApiFivePlus.java

public static Notification createSimpleNotification(Context context, String title, String text,
        PendingIntent intent) {// w  w w .ja  va  2 s.c  om
    NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.logo_linphone_57x57).setContentTitle(title).setContentText(text)
            .setContentIntent(intent);

    Notification notif = notifBuilder.build();
    notif.defaults |= Notification.DEFAULT_VIBRATE;
    notif.defaults |= Notification.DEFAULT_SOUND;
    notif.defaults |= Notification.DEFAULT_LIGHTS;

    return notif;
}

From source file:com.razza.apps.iosched.service.SessionAlarmService.java

/**
 *  A starred session is about to end. Notify the user to provide session feedback.
 *  Constructs and triggers a system notification. Does nothing if the session has already
 *  concluded./*w w w.j  a v  a  2s  .co m*/
 */
private void notifySessionFeedback(boolean debug) {
    LogUtils.LOGD(TAG, "Considering firing notification for session feedback.");

    if (debug) {
        LogUtils.LOGW(TAG, "Note: this is a debug notification.");
    }

    // Don't fire notification if this feature is disabled in settings
    if (!SettingsUtils.shouldShowSessionFeedbackReminders(this)) {
        LogUtils.LOGD(TAG, "Skipping session feedback notification. Disabled in settings.");
        return;
    }

    Cursor c = null;
    try {
        c = getContentResolver().query(ScheduleContract.Sessions.CONTENT_MY_SCHEDULE_URI,
                SessionsNeedingFeedbackQuery.PROJECTION, SessionsNeedingFeedbackQuery.WHERE_CLAUSE, null, null);
        if (c == null) {
            return;
        }

        FeedbackHelper feedbackHelper = new FeedbackHelper(this);

        List<String> needFeedbackIds = new ArrayList<String>();
        List<String> needFeedbackTitles = new ArrayList<String>();
        while (c.moveToNext()) {
            String sessionId = c.getString(SessionsNeedingFeedbackQuery.SESSION_ID);
            String sessionTitle = c.getString(SessionsNeedingFeedbackQuery.SESSION_TITLE);

            // Avoid repeated notifications.
            if (feedbackHelper.isFeedbackNotificationFiredForSession(sessionId)) {
                LogUtils.LOGD(TAG,
                        "Skipping repeated session feedback notification for session '" + sessionTitle + "'");
                continue;
            }

            needFeedbackIds.add(sessionId);
            needFeedbackTitles.add(sessionTitle);
        }

        if (needFeedbackIds.size() == 0) {
            // the user has already been notified of all sessions needing feedback
            return;
        }

        LogUtils.LOGD(TAG, "Going forward with session feedback notification for " + needFeedbackIds.size()
                + " session(s).");

        final Resources res = getResources();

        // this is used to synchronize deletion of notifications on phone and wear
        Intent dismissalIntent = new Intent(ACTION_NOTIFICATION_DISMISSAL);
        // TODO: fix Wear dismiss integration
        //dismissalIntent.putExtra(KEY_SESSION_ID, sessionId);
        PendingIntent dismissalPendingIntent = PendingIntent.getService(this, (int) new Date().getTime(),
                dismissalIntent, PendingIntent.FLAG_UPDATE_CURRENT);

        String provideFeedbackTicker = res.getString(R.string.session_feedback_notification_ticker);
        NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(this)
                .setColor(getResources().getColor(R.color.theme_primary)).setContentText(provideFeedbackTicker)
                .setTicker(provideFeedbackTicker)
                .setLights(SessionAlarmService.NOTIFICATION_ARGB_COLOR,
                        SessionAlarmService.NOTIFICATION_LED_ON_MS, SessionAlarmService.NOTIFICATION_LED_OFF_MS)
                .setSmallIcon(R.drawable.ic_stat_notification).setPriority(Notification.PRIORITY_LOW)
                .setLocalOnly(true) // make it local to the phone
                .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE)
                .setDeleteIntent(dismissalPendingIntent).setAutoCancel(true);

        if (needFeedbackIds.size() == 1) {
            // Only 1 session needs feedback
            Uri sessionUri = ScheduleContract.Sessions.buildSessionUri(needFeedbackIds.get(0));
            PendingIntent pi = TaskStackBuilder.create(this)
                    .addNextIntent(new Intent(this, MyScheduleActivity.class))
                    .addNextIntent(
                            new Intent(Intent.ACTION_VIEW, sessionUri, this, SessionFeedbackActivity.class))
                    .getPendingIntent(1, PendingIntent.FLAG_CANCEL_CURRENT);

            notifBuilder.setContentTitle(needFeedbackTitles.get(0)).setContentIntent(pi);
        } else {
            // Show information about several sessions that need feedback
            PendingIntent pi = TaskStackBuilder.create(this)
                    .addNextIntent(new Intent(this, MyScheduleActivity.class))
                    .getPendingIntent(1, PendingIntent.FLAG_CANCEL_CURRENT);

            NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
            inboxStyle.setBigContentTitle(provideFeedbackTicker);
            for (String title : needFeedbackTitles) {
                inboxStyle.addLine(title);
            }

            notifBuilder
                    .setContentTitle(getResources().getQuantityString(R.plurals.session_plurals,
                            needFeedbackIds.size(), needFeedbackIds.size()))
                    .setStyle(inboxStyle).setContentIntent(pi);
        }

        NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        LogUtils.LOGD(TAG, "Now showing session feedback notification!");
        nm.notify(FEEDBACK_NOTIFICATION_ID, notifBuilder.build());

        for (int i = 0; i < needFeedbackIds.size(); i++) {
            setupNotificationOnWear(needFeedbackIds.get(i), null, needFeedbackTitles.get(i), null);
            feedbackHelper.setFeedbackNotificationAsFiredForSession(needFeedbackIds.get(i));
        }
    } finally {
        if (c != null) {
            try {
                c.close();
            } catch (Exception ignored) {
            }
        }
    }
}