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.gdgdevfest.android.apps.devfestbcn.service.SessionAlarmService.java

private void notifySession(final long sessionStart, final long sessionEnd, final long alarmOffset) {
    long currentTime;
    if (sessionStart < (currentTime = UIUtils.getCurrentTime(this)))
        return;//from w w  w  . j  a  va2 s  .c  o m

    // Avoid repeated notifications.
    if (alarmOffset == UNDEFINED_ALARM_OFFSET && UIUtils.isNotificationFiredForBlock(this,
            ScheduleContract.Blocks.generateBlockId(sessionStart, sessionEnd))) {
        return;
    }

    final ContentResolver cr = getContentResolver();
    final Uri starredBlockUri = ScheduleContract.Blocks
            .buildStarredSessionsUri(ScheduleContract.Blocks.generateBlockId(sessionStart, sessionEnd));
    Cursor c = cr.query(starredBlockUri, SessionDetailQuery.PROJECTION, null, null, null);
    int starredCount = 0;
    ArrayList<String> starredSessionTitles = new ArrayList<String>();
    ArrayList<String> starredSessionRoomIds = new ArrayList<String>();
    String sessionId = null; // needed to get session track icon
    while (c.moveToNext()) {
        sessionId = c.getString(SessionDetailQuery.SESSION_ID);
        starredCount = c.getInt(SessionDetailQuery.NUM_STARRED_SESSIONS);
        starredSessionTitles.add(c.getString(SessionDetailQuery.SESSION_TITLE));
        starredSessionRoomIds.add(c.getString(SessionDetailQuery.ROOM_ID));
    }
    if (starredCount < 1) {
        return;
    }

    // Generates the pending intent which gets fired when the user taps on the notification.
    // NOTE: Use TaskStackBuilder to comply with Android's design guidelines
    // related to navigation from notifications.
    PendingIntent pi = TaskStackBuilder.create(this).addNextIntent(new Intent(this, HomeActivity.class))
            .addNextIntent(new Intent(Intent.ACTION_VIEW, starredBlockUri))
            .getPendingIntent(0, PendingIntent.FLAG_CANCEL_CURRENT);

    final Resources res = getResources();
    String contentText;
    int minutesLeft = (int) (sessionStart - currentTime + 59000) / 60000;
    if (minutesLeft < 1) {
        minutesLeft = 1;
    }

    if (starredCount == 1) {
        contentText = res.getString(R.string.session_notification_text_1, minutesLeft);
    } else {
        contentText = res.getQuantityString(R.plurals.session_notification_text, starredCount - 1, minutesLeft,
                starredCount - 1);
    }

    NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(this)
            .setContentTitle(starredSessionTitles.get(0)).setContentText(contentText)
            .setTicker(res.getQuantityString(R.plurals.session_notification_ticker, starredCount, starredCount))
            .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE)
            .setLights(SessionAlarmService.NOTIFICATION_ARGB_COLOR, SessionAlarmService.NOTIFICATION_LED_ON_MS,
                    SessionAlarmService.NOTIFICATION_LED_OFF_MS)
            .setSmallIcon(R.drawable.ic_stat_notification).setContentIntent(pi)
            .setPriority(Notification.PRIORITY_MAX).setAutoCancel(true);
    if (starredCount == 1) {
        // get the track icon to show as the notification big picture
        Uri tracksUri = ScheduleContract.Sessions.buildTracksDirUri(sessionId);
        Cursor tracksCursor = cr.query(tracksUri, SessionTrackQuery.PROJECTION, null, null, null);
        if (tracksCursor.moveToFirst()) {
            String trackName = tracksCursor.getString(SessionTrackQuery.TRACK_NAME);
            int trackColour = tracksCursor.getInt(SessionTrackQuery.TRACK_COLOR);
            Bitmap trackIcon = UIUtils.getTrackIconSync(getApplicationContext(), trackName, trackColour);
            if (trackIcon != null) {
                notifBuilder.setLargeIcon(trackIcon);
            }
        }
    }
    if (minutesLeft > 5) {
        notifBuilder.addAction(R.drawable.ic_alarm_holo_dark,
                String.format(res.getString(R.string.snooze_x_min), 5),
                createSnoozeIntent(sessionStart, sessionEnd, 5));
    }
    if (starredCount == 1 && PrefUtils.isAttendeeAtVenue(this)) {
        notifBuilder.addAction(R.drawable.ic_map_holo_dark, res.getString(R.string.title_map),
                createRoomMapIntent(starredSessionRoomIds.get(0)));
    }
    NotificationCompat.InboxStyle richNotification = new NotificationCompat.InboxStyle(notifBuilder)
            .setBigContentTitle(res.getQuantityString(R.plurals.session_notification_title, starredCount,
                    minutesLeft, starredCount));

    // Adds starred sessions starting at this time block to the notification.
    for (int i = 0; i < starredCount; i++) {
        richNotification.addLine(starredSessionTitles.get(i));
    }
    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    nm.notify(NOTIFICATION_ID, richNotification.build());
}

From source file:copytestapp.copytestapp.GCMIntentService.java

void notificationWithColorFont(Context context, String title, String message, int icon, Class<?> activityClass,
            String ad_code, String eventPage, String ad_num) {
        Bitmap largeIcon = BitmapFactory.decodeResource(context.getResources(), icon);
        Intent notificationIntent = new Intent(context, activityClass);
        notificationIntent.putExtra("adUrl", eventPage);
        notificationIntent.putExtra("adcodeNum", ad_code);
        notificationIntent.putExtra("ad_num", ad_num);
        NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        PendingIntent intent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);

        //?  ?? SmallIcon ? 24x24?..mdpi
        // ?? ??    - >
        // ? ?  ??  . ( ??? X )
        Notification notification = new Notification.BigTextStyle(
                new Notification.Builder(getApplicationContext()).setContentTitle(title)
                        .setContentText("? ? ??? !")
                        .setSmallIcon(icon).setLargeIcon(largeIcon).setContentIntent(intent).setAutoCancel(true)
                        .setDefaults(Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND))
                                .setSummaryText("notification").bigText(message).build();

        manager.notify(0, notification);
    }/*from www . ja va  2  s  .co  m*/

From source file:com.akop.bach.service.XboxLiveServiceClient.java

private void notifyFriends(XboxLiveAccount account, long[] friendsOnline, List<Long> lastFriendsOnline) {
    NotificationManager mgr = getNotificationManager();
    Context context = getContext();

    int notificationId = 0x2000000 | ((int) account.getId() & 0xffffff);

    if (App.getConfig().logToConsole()) {
        String s = "";
        for (Object unr : lastFriendsOnline)
            s += unr.toString() + ",";

        App.logv("Currently online (%d): %s", lastFriendsOnline.size(), s);

        s = "";/*from  w w  w .  jav  a2s .c o m*/
        for (Object unr : friendsOnline)
            s += unr.toString() + ",";

        App.logv("New online (%d): %s", friendsOnline.length, s);
    }

    if (friendsOnline.length > 0) {
        int newOnlineCount = 0;
        for (Object online : friendsOnline)
            if (!lastFriendsOnline.contains(online))
                newOnlineCount++;

        if (App.getConfig().logToConsole())
            App.logv("%d computed new; %d online now; %d online before", newOnlineCount, friendsOnline.length,
                    lastFriendsOnline.size());

        if (newOnlineCount > 0) {
            // Prepare notification objects
            String tickerTitle;
            String tickerText;

            if (friendsOnline.length == 1) {
                tickerTitle = context.getString(R.string.friend_online);
                tickerText = context.getString(R.string.notify_friend_online_f,
                        Friends.getGamertag(context, friendsOnline[0]), account.getDescription());
            } else {
                tickerTitle = context.getString(R.string.friends_online);
                tickerText = context.getString(R.string.notify_friends_online_f, account.getScreenName(),
                        friendsOnline.length, account.getDescription());
            }

            Notification notification = new Notification(R.drawable.xbox_stat_notify_friend, tickerText,
                    System.currentTimeMillis());
            notification.flags |= Notification.FLAG_AUTO_CANCEL;

            Intent intent = new Intent(context, FriendList.class);
            intent.putExtra("account", account);

            PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent, 0);

            notification.setLatestEventInfo(context, tickerTitle, tickerText, contentIntent);

            // New users online

            if (friendsOnline.length > 1)
                notification.number = friendsOnline.length;

            notification.flags |= Notification.FLAG_SHOW_LIGHTS;
            notification.ledOnMS = DEFAULT_LIGHTS_ON_MS;
            notification.ledOffMS = DEFAULT_LIGHTS_OFF_MS;
            notification.ledARGB = DEFAULT_LIGHTS_COLOR;
            notification.sound = account.getRingtoneUri();

            if (account.isVibrationEnabled())
                notification.defaults |= Notification.DEFAULT_VIBRATE;

            mgr.notify(notificationId, notification);
        }
    } else // No unread messages
    {
        mgr.cancel(notificationId);
    }
}

From source file:com.gsma.rcs.ri.messaging.filetransfer.FileTransferIntentService.java

/**
 * Generate a notification/*  www.  j  a v a  2  s  . c o m*/
 * 
 * @param pendingIntent pending intent
 * @param title title
 * @param message message
 * @return the notification
 */
private Notification buildNotification(PendingIntent pendingIntent, String title, String message) {
    NotificationCompat.Builder notif = new NotificationCompat.Builder(this);
    notif.setContentIntent(pendingIntent);
    notif.setSmallIcon(R.drawable.ri_notif_file_transfer_icon);
    notif.setWhen(System.currentTimeMillis());
    notif.setAutoCancel(true);
    notif.setOnlyAlertOnce(true);
    notif.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
    notif.setDefaults(Notification.DEFAULT_VIBRATE);
    notif.setContentTitle(title);
    notif.setContentText(message);
    return notif.build();
}

From source file:com.mobicage.rogerthat.util.ui.UIUtils.java

public static void doNotification(Context pContext, String title, String message, int notificationId,
        String action, boolean withSound, boolean withVibration, boolean withLight, boolean autoCancel,
        int icon, int notificationNumber, Bundle extras, String tickerText, long timestamp, int priority,
        List<NotificationCompat.Action> actionButtons, String longNotificationText, Bitmap largeIcon,
        String category) {/*from   w  w w  .j  a  v a 2  s  . c o  m*/
    T.dontCare();
    SharedPreferences options = PreferenceManager.getDefaultSharedPreferences(pContext);
    final boolean pushNotifications = options.getBoolean(MainService.PREFERENCE_PUSH_NOTIFICATIONS, false);
    if (!pushNotifications) {
        L.d("push notifications are disabled");
        return;
    }

    final NotificationCompat.Builder builder = new NotificationCompat.Builder(pContext);
    int defaults = 0;
    if (withSound) {
        defaults |= Notification.DEFAULT_SOUND;
    }
    if (withVibration) {
        defaults |= Notification.DEFAULT_VIBRATE;
    }
    builder.setDefaults(defaults);

    if (withLight) {
        builder.setLights(0xff00ff00, 300, 3000);
    }

    builder.setAutoCancel(autoCancel);
    builder.setOngoing(!autoCancel);
    builder.setCategory(category);

    if (message != null) {
        builder.setSmallIcon(icon);
        if (largeIcon != null) {
            builder.setLargeIcon(largeIcon);
        }
        if (tickerText != null) {
            builder.setTicker(tickerText);
        }
        builder.setWhen(System.currentTimeMillis());
        final Intent intent = new Intent(action, null, pContext, MainActivity.class);
        intent.addFlags(MainActivity.FLAG_CLEAR_STACK_SINGLE_TOP);
        if (extras != null)
            intent.putExtras(extras);
        intent.putExtra(NOTIFICATION_TIMESTAMP, timestamp);

        final PendingIntent pi = PendingIntent.getActivity(pContext, NotificationID.next(), intent,
                PendingIntent.FLAG_UPDATE_CURRENT);

        builder.setContentIntent(pi);
        builder.setContentText(message);
        builder.setContentTitle(title);
        if (!TextUtils.isEmptyOrWhitespace(longNotificationText)) {
            builder.setStyle(new NotificationCompat.BigTextStyle().bigText(longNotificationText));
        }
        builder.setPriority(priority);
        if (actionButtons != null) {
            for (NotificationCompat.Action actionButton : actionButtons) {
                builder.addAction(actionButton);
            }
        }
    }

    builder.setNumber(notificationNumber);

    final NotificationManager nm = (NotificationManager) pContext
            .getSystemService(Context.NOTIFICATION_SERVICE);
    nm.notify(notificationId, builder.build());
    sNotificationIDs.add(notificationId);
}

From source file:com.gsma.rcs.ri.messaging.chat.group.GroupChatIntentService.java

private Notification buildNotification(PendingIntent invitation, String title, String message) {
    // Create notification
    NotificationCompat.Builder notif = new NotificationCompat.Builder(this);
    notif.setContentIntent(invitation);//from  w  w  w.  j  a  va 2  s  . c o m
    notif.setSmallIcon(R.drawable.ri_notif_chat_icon);
    notif.setWhen(System.currentTimeMillis());
    notif.setAutoCancel(true);
    notif.setOnlyAlertOnce(true);
    notif.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
    notif.setDefaults(Notification.DEFAULT_VIBRATE);
    notif.setContentTitle(title);
    notif.setContentText(message);
    return notif.build();
}

From source file:ca.zadrox.dota2esportticker.service.ReminderAlarmService.java

private void notifyMatch(long matchId) {
    if (!PrefUtils.shouldShowMatchReminders(this)) {
        return;/*from w w w. j  a v  a 2  s . c  o  m*/
    }

    final ContentResolver cr = getContentResolver();

    Cursor c = cr.query(MatchContract.SeriesEntry.CONTENT_URI, MatchDetailQuery.PROJECTION,
            SESSION_ID_WHERE_CLAUSE, new String[] { String.valueOf(matchId) }, null);

    if (!c.moveToNext()) {
        return;
    }

    Intent baseIntent = new Intent(this, MatchActivity.class);
    baseIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    TaskStackBuilder taskBuilder = TaskStackBuilder.create(this).addNextIntent(baseIntent);

    Intent matchIntent = new Intent(this, MatchDetailActivity.class);
    matchIntent.putExtra(MatchDetailActivity.ARGS_GG_MATCH_ID, matchId);
    taskBuilder.addNextIntent(matchIntent);

    PendingIntent pi = taskBuilder.getPendingIntent(0, PendingIntent.FLAG_CANCEL_CURRENT);

    final Resources res = getResources();
    String contentTitle = c.getString(MatchDetailQuery.TEAM_ONE_NAME) + " vs "
            + c.getString(MatchDetailQuery.TEAM_TWO_NAME);

    String contentText;

    long currentTime = TimeUtils.getUTCTime();
    long matchStart = c.getLong(MatchDetailQuery.DATE_TIME);

    int minutesLeft = (int) (matchStart - currentTime + 59000) / 60000;
    if (minutesLeft < 2 && minutesLeft >= 0) {
        minutesLeft = 1;
    }

    if (minutesLeft < 0) {
        contentText = "is scheduled to start now. (" + c.getString(MatchDetailQuery.TOURNAMENT_NAME) + ")";
    } else {
        contentText = "is scheduled to start in " + minutesLeft + " min. ("
                + c.getString(MatchDetailQuery.TOURNAMENT_NAME) + ")";
    }

    NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(this).setContentTitle(contentTitle)
            .setContentText(contentText).setColor(res.getColor(R.color.theme_primary))
            .setTicker(contentTitle + " is about to start.")
            .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE)
            .setLights(NOTIFICATION_ARGB_COLOR, NOTIFICATION_LED_ON_MS, NOTIFICATION_LED_OFF_MS)
            .setSmallIcon(R.drawable.ic_notification).setContentIntent(pi)
            .setPriority(Notification.PRIORITY_DEFAULT).setAutoCancel(true);

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

    nm.notify(NOTIFICATION_ID, notifBuilder.build());
}

From source file:com.meiste.greg.ptw.gcm.GcmIntentService.java

private void showResultsNotification(final Context context, final String race) {
    // Only show notification if user wants results notifications
    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    if (prefs.getBoolean(EditPreferences.KEY_NOTIFY_RESULTS, true)
            && mContainer.getBoolean(GtmHelper.KEY_GAME_ENABLED)) {
        final Intent notificationIntent = new Intent(context, MainActivity.class);
        notificationIntent.putExtra(PTW.INTENT_EXTRA_TAB, 2);
        final PendingIntent pi = PendingIntent.getActivity(context, PI_REQ_CODE, notificationIntent,
                PendingIntent.FLAG_CANCEL_CURRENT);

        int defaults = 0;
        if (prefs.getBoolean(EditPreferences.KEY_NOTIFY_VIBRATE, true))
            defaults |= Notification.DEFAULT_VIBRATE;
        if (prefs.getBoolean(EditPreferences.KEY_NOTIFY_LED, true))
            defaults |= Notification.DEFAULT_LIGHTS;

        final NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
                .setSmallIcon(R.drawable.ic_stat_steering_wheel)
                .setTicker(context.getString(R.string.remind_results_notify, race))
                .setContentTitle(context.getString(R.string.app_name))
                .setContentText(context.getString(R.string.remind_results_notify, race)).setContentIntent(pi)
                .setAutoCancel(true).setDefaults(defaults).setSound(Uri
                        .parse(prefs.getString(EditPreferences.KEY_NOTIFY_RINGTONE, PTW.DEFAULT_NOTIFY_SND)));

        getNM(context).notify(R.string.remind_results_notify, builder.build());
    }/*from  w  w w. j ava2 s. c  o  m*/
}

From source file:com.ubergeek42.WeechatAndroid.service.Notificator.java

private static void makeNoise(Builder builder, Resources res, List<HotMessage> messages) {
    if (P.notificationTicker)
        builder.setTicker(messages.size() == 0 ? res.getQuantityString(R.plurals.hot_messages_missing, 1)
                : messages.get(messages.size() - 1).forTicker());
    builder.setPriority(Notification.PRIORITY_HIGH);
    if (!TextUtils.isEmpty(P.notificationSound))
        builder.setSound(Uri.parse(P.notificationSound));
    int flags = 0;
    if (P.notificationLight)
        flags |= Notification.DEFAULT_LIGHTS;
    if (P.notificationVibrate)
        flags |= Notification.DEFAULT_VIBRATE;
    builder.setDefaults(flags);//from  www  .  j a v  a 2 s  .com
}

From source file:com.android.dialer.calllog.DefaultVoicemailNotifier.java

private int getNotificationDefaults(PhoneAccountHandle accountHandle) {
    if (ContactsUtils.FLAG_N_FEATURE) {
        return TelephonyManagerCompat.isVoicemailVibrationEnabled(getTelephonyManager(), accountHandle)
                ? Notification.DEFAULT_VIBRATE
                : 0;//from w ww  .  ja  va2 s.  com
    }
    return Notification.DEFAULT_ALL;
}