Example usage for android.app Notification FLAG_SHOW_LIGHTS

List of usage examples for android.app Notification FLAG_SHOW_LIGHTS

Introduction

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

Prototype

int FLAG_SHOW_LIGHTS

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

Click Source Link

Document

Bit to be bitwise-ored into the #flags field that should be set if you want the LED on for this notification.

Usage

From source file:com.nanostuffs.yurdriver.GCMIntentService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 *//*from w  w w  . ja v  a2s  .  c  om*/
private void generateNotification(Context context, String message) {
    int icon = R.drawable.ic_launcher;
    long when = System.currentTimeMillis();
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification(icon, message, when);
    String title = context.getString(R.string.app_name);
    Intent notificationIntent = new Intent(context, MapActivity.class);
    notificationIntent.putExtra("fromNotification", "notification");
    // set intent so it does not start a new activity
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    notification.setLatestEventInfo(context, title, message, intent);
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    System.out.println("notification====>" + message);
    notification.defaults |= Notification.DEFAULT_SOUND;
    notification.defaults |= Notification.DEFAULT_VIBRATE;
    // notification.defaults |= Notification.DEFAULT_LIGHTS;
    notification.flags |= Notification.FLAG_SHOW_LIGHTS;
    notification.ledARGB = 0x00000000;
    notification.ledOnMS = 0;
    notification.ledOffMS = 0;
    notificationManager.notify(AndyConstants.NOTIFICATION_ID, notification);
    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock wakeLock = pm.newWakeLock(
            PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE,
            "WakeLock");
    wakeLock.acquire();
    wakeLock.release();

}

From source file:foam.zizim.android.BoskoiService.java

private void showNotification(String tickerText) {
    // This is what should be launched if the user selects our notification.
    Intent baseIntent = new Intent(this, IncidentsTab.class);
    baseIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, baseIntent, 0);

    // choose the ticker text
    newBoskoiReportNotification = new Notification(R.drawable.favicon, tickerText, System.currentTimeMillis());
    newBoskoiReportNotification.contentIntent = contentIntent;
    newBoskoiReportNotification.flags = Notification.FLAG_AUTO_CANCEL;
    newBoskoiReportNotification.defaults = Notification.DEFAULT_ALL;
    newBoskoiReportNotification.setLatestEventInfo(this, TAG, tickerText, contentIntent);
    if (ringtone) {
        // set the ringer
        Uri ringURI = Uri.fromFile(new File("/system/media/audio/ringtones/ringer.mp3"));
        newBoskoiReportNotification.sound = ringURI;
    }/* ww  w . j  a va 2s .  c  o  m*/

    if (vibrate) {
        double vibrateLength = 100 * Math.exp(0.53 * 20);
        long[] vibrate = new long[] { 100, 100, (long) vibrateLength };
        newBoskoiReportNotification.vibrate = vibrate;

        if (flashLed) {
            int color = Color.BLUE;
            newBoskoiReportNotification.ledARGB = color;
        }

        newBoskoiReportNotification.ledOffMS = (int) vibrateLength;
        newBoskoiReportNotification.ledOnMS = (int) vibrateLength;
        newBoskoiReportNotification.flags = newBoskoiReportNotification.flags | Notification.FLAG_SHOW_LIGHTS;
    }

    mNotificationManager.notify(NOTIFICATION_ID, newBoskoiReportNotification);
}

From source file:org.transdroid.service.UpdateService.java

private void newNotification(String ticker, String title, String text, String downloadUrl, int notifyID) {

    // Use the alarm service settings for the notification sound/vibrate/colour
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    AlarmSettings settings = Preferences.readAlarmSettings(prefs);

    // Set up an intent that will initiate a download of the new version
    Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(downloadUrl));

    // Create a new notification
    Notification newNotification = new Notification(R.drawable.icon_notification, ticker,
            System.currentTimeMillis());
    newNotification.flags = Notification.FLAG_AUTO_CANCEL;
    newNotification.setLatestEventInfo(getApplicationContext(), title, text,
            PendingIntent.getActivity(getApplicationContext(), notifyID, i, 0));

    // Get the system notification manager, if not done so previously
    if (notificationManager == null) {
        notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    }//www. ja v  a2 s . co m

    // If sound enabled add to notification
    if (settings.getAlarmPlaySound() && settings.getAlarmSoundURI() != null) {
        newNotification.sound = Uri.parse(settings.getAlarmSoundURI());
    }

    // If vibration enabled add to notification
    if (settings.getAlarmVibrate()) {
        newNotification.defaults = Notification.DEFAULT_VIBRATE;
    }

    // Add coloured light; defaults to 0xff7dbb21
    newNotification.ledARGB = settings.getAlarmColour();
    newNotification.ledOnMS = 600;
    newNotification.ledOffMS = 1000;
    newNotification.flags |= Notification.FLAG_SHOW_LIGHTS;

    // Send notification
    notificationManager.notify(notifyID, newNotification);

}

From source file:com.testpush.notification.GcmIntentService.java

private void sendNotification(String titre, String message, String image, String id) {
    mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

    Log.d("GCM", "NOTIFICATION");

    //afficher la notif

    try {//from  w w w. j ava 2  s . c  o  m
        //Vibrator v = (Vibrator) this.getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE);
        // Vibrate for 500 milliseconds
        //v.vibrate(new long[]{0,100,300,200},-1);
    } catch (Exception e) {
    }

    PackageManager pm = getPackageManager();
    Intent lancement = new Intent(this.getApplicationContext(), MainActivity.class);
    lancement.putExtra("LAUNCH_NOTIFICATION", true);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, lancement, 0);

    Bitmap bitmap = getBitmapFromURL(image);

    Notification notif;
    {
        notif = new NotificationCompat.Builder(this).setSmallIcon(R.mipmap.ic_launcher).setLargeIcon(bitmap)
                .setColor(Color.GRAY).setContentTitle(titre).setContentText(message)
                .setContentIntent(contentIntent).build();

        notif.ledARGB = Color.GRAY;
        notif.flags = Notification.FLAG_SHOW_LIGHTS;
        notif.ledOnMS = 750;
        notif.ledOffMS = 2000;

    }

    //TODO mettre le nombre et un id diffrent
    notif.flags |= Notification.FLAG_AUTO_CANCEL;

    if (id == null)
        id = "";

    mNotificationManager.notify(id, id.hashCode(), notif);

}

From source file:uk.org.rivernile.edinburghbustracker.android.alerts.TimeAlertService.java

/**
 * {@inheritDoc}// w ww .j  a  v a 2  s.co  m
 */
@Override
protected void onHandleIntent(final Intent intent) {
    final String stopCode = intent.getStringExtra(ARG_STOPCODE);
    final String[] services = intent.getStringArrayExtra(ARG_SERVICES);
    final int timeTrigger = intent.getIntExtra(ARG_TIME_TRIGGER, 5);
    final BusParser parser = new EdinburghParser();

    HashMap<String, BusStop> result;
    try {
        // Get the bus times. Only get 1 bus per service.
        result = parser.getBusStopData(new String[] { stopCode }, 1);
    } catch (BusParserException e) {
        // There was an error. No point continuing. Reschedule.
        reschedule(intent);
        return;
    }

    // Get the bus stop we are interested in. It should be the only one in
    // the HashMap anyway.
    final BusStop busStop = result.get(stopCode);
    int time;
    EdinburghBus edinBs;

    // Loop through all the bus services at this stop.
    for (BusService bs : busStop.getBusServices()) {
        // We are only interested in the next departure. Also get the time.
        edinBs = (EdinburghBus) bs.getFirstBus();
        if (edinBs == null) {
            continue;
        }

        time = edinBs.getArrivalMinutes();

        // Loop through all of the services we are interested in.
        for (String service : services) {
            // The service matches and meets the time criteria.
            if (service.equals(bs.getServiceName()) && time <= timeTrigger) {
                // The alert may have been cancelled by the user recently,
                // check it's still active to stay relevant. Cancel the
                // alert if we're continuing.
                if (!sd.isActiveTimeAlert(stopCode))
                    return;
                alertMan.removeTimeAlert();

                // Create the intent that's fired when the notification is
                // tapped. It shows the bus times view for that stop.
                final Intent launchIntent = new Intent(this, DisplayStopDataActivity.class);
                launchIntent.setAction(DisplayStopDataActivity.ACTION_VIEW_STOP_DATA);
                launchIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                launchIntent.putExtra(DisplayStopDataActivity.ARG_STOPCODE, stopCode);
                launchIntent.putExtra(DisplayStopDataActivity.ARG_FORCELOAD, true);

                final String stopName = bsd.getNameForBusStop(stopCode);

                final String title = getString(R.string.timeservice_notification_title);

                final String summary = getResources().getQuantityString(
                        R.plurals.timeservice_notification_summary, time == 0 ? 1 : time, service, time,
                        stopName);

                // Build the notification.
                final NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(this);
                notifBuilder.setAutoCancel(true);
                notifBuilder.setSmallIcon(R.drawable.ic_status_bus);
                notifBuilder.setTicker(summary);
                notifBuilder.setContentTitle(title);
                notifBuilder.setContentText(summary);
                // Support for Jelly Bean notifications.
                notifBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(summary));
                notifBuilder.setContentIntent(
                        PendingIntent.getActivity(this, 0, launchIntent, PendingIntent.FLAG_ONE_SHOT));

                final Notification n = notifBuilder.build();
                if (sp.getBoolean(PreferencesActivity.PREF_ALERT_SOUND, true))
                    n.defaults |= Notification.DEFAULT_SOUND;

                if (sp.getBoolean(PreferencesActivity.PREF_ALERT_VIBRATE, true))
                    n.defaults |= Notification.DEFAULT_VIBRATE;

                if (sp.getBoolean(PreferencesActivity.PREF_ALERT_LED, true)) {
                    n.defaults |= Notification.DEFAULT_LIGHTS;
                    n.flags |= Notification.FLAG_SHOW_LIGHTS;
                }

                // Send the notification.
                notifMan.notify(ALERT_ID, n);
                return;
            }
        }
    }

    // All the services have been looped through and the criteria didn't
    // match. This means a reschedule should be attempted.
    reschedule(intent);
}

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  www  .j  a v a2  s  .com
        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:org.onebusaway.android.directions.realtime.RealtimeService.java

private void showNotification(ItineraryDescription description, int title, int message,
        Class<? extends Activity> notificationTarget, Bundle params, List<Itinerary> itineraries) {

    String titleText = getResources().getString(title);
    String messageText = getResources().getString(message);

    Intent openIntent = new Intent(getApplicationContext(), notificationTarget);
    openIntent.putExtras(params);/*from   ww w .j av a2 s.co  m*/
    openIntent.putExtra(OTPConstants.INTENT_SOURCE, OTPConstants.Source.NOTIFICATION);
    openIntent.putExtra(OTPConstants.ITINERARIES, (ArrayList<Itinerary>) itineraries);
    openIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent openPendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, openIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getApplicationContext())
            .setSmallIcon(R.drawable.ic_stat_notification).setContentTitle(titleText)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(messageText)).setContentText(messageText)
            .setPriority(NotificationCompat.PRIORITY_MAX).setContentIntent(openPendingIntent);

    NotificationManager notificationManager = (NotificationManager) getApplicationContext()
            .getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = mBuilder.build();
    notification.defaults = Notification.DEFAULT_ALL;
    notification.flags |= Notification.FLAG_AUTO_CANCEL | Notification.FLAG_SHOW_LIGHTS;

    Integer notificationId = description.getId();
    notificationManager.notify(notificationId, notification);
}

From source file:org.yaaic.irc.IRCService.java

/**
 * Update notification and vibrate and/or flash a LED light if needed
 *
 * @param text       The ticker text to display
 * @param contentText       The text to display in the notification dropdown
 * @param vibrate True if the device should vibrate, false otherwise
 * @param sound True if the device should make sound, false otherwise
 * @param light True if the device should flash a LED light, false otherwise
 *///from  w  w w . jav a  2  s  . c  o m
private void updateNotification(String text, String contentText, boolean vibrate, boolean sound,
        boolean light) {
    if (foreground) {
        Intent notifyIntent = new Intent(this, MainActivity.class);
        notifyIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notifyIntent, 0);

        if (contentText == null) {
            if (newMentions >= 1) {
                StringBuilder sb = new StringBuilder();
                for (Conversation conv : mentions.values()) {
                    sb.append(conv.getName() + " (" + conv.getNewMentions() + "), ");
                }
                contentText = getString(R.string.notification_mentions, sb.substring(0, sb.length() - 2));
            } else if (!connectedServerTitles.isEmpty()) {
                StringBuilder sb = new StringBuilder();
                for (String title : connectedServerTitles) {
                    sb.append(title + ", ");
                }
                contentText = getString(R.string.notification_connected, sb.substring(0, sb.length() - 2));
            } else {
                contentText = getString(R.string.notification_not_connected);
            }
        }

        notification = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_notification)
                .setContentTitle(getText(R.string.app_name)).setContentText(contentText)
                .setContentIntent(contentIntent).setWhen(System.currentTimeMillis())
                .setPriority(mentions.size() > 0 ? NotificationCompat.PRIORITY_DEFAULT
                        : NotificationCompat.PRIORITY_MIN)
                .setCategory(NotificationCompat.CATEGORY_PROGRESS).build();

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

        if (sound) {
            notification.defaults |= Notification.DEFAULT_SOUND;
        }

        if (light) {
            notification.ledARGB = NOTIFICATION_LED_COLOR;
            notification.ledOnMS = NOTIFICATION_LED_ON_MS;
            notification.ledOffMS = NOTIFICATION_LED_OFF_MS;
            notification.flags |= Notification.FLAG_SHOW_LIGHTS;
        }

        notification.number = newMentions;

        notificationManager.notify(FOREGROUND_NOTIFICATION, notification);
    }
}

From source file:com.bluelinelabs.logansquare.typeconverters.NotificationConverter.java

@TargetApi(Build.VERSION_CODES.KITKAT)
@NonNull/*from  ww w .  j  a v a 2 s.c  o m*/
public static SimpleNotification toSimpleNotification(@NonNull Notification notification) {
    SimpleNotification simpleNotification = new SimpleNotification();

    simpleNotification.autoCancel = (notification.flags
            & Notification.FLAG_AUTO_CANCEL) == Notification.FLAG_AUTO_CANCEL;
    android.util.Log.d("json2notification", "autoCancel:" + simpleNotification.autoCancel);

    //simpleNotification.bigPictureStyle // TODO

    simpleNotification.category = notification.category;
    simpleNotification.color = notification.color > 0 ? notification.color : null;
    simpleNotification.contentInfo = notification.extras.getString(Notification.EXTRA_INFO_TEXT);
    simpleNotification.contentIntent = notification.contentIntent;
    simpleNotification.contentTitle = notification.extras.getString(Notification.EXTRA_TITLE);
    simpleNotification.contentText = notification.extras.getString(Notification.EXTRA_TEXT);
    simpleNotification.defaults = notification.defaults > 0 ? notification.defaults : null;
    simpleNotification.deleteIntent = notification.deleteIntent;
    //simpleNotification.extras;
    simpleNotification.groupKey = notification.getGroup();
    if (simpleNotification.groupKey != null) {
        simpleNotification.groupSummary = (notification.flags
                & Notification.FLAG_GROUP_SUMMARY) == Notification.FLAG_GROUP_SUMMARY;
    }
    Bitmap bitmap = notification.extras.getParcelable(Notification.EXTRA_LARGE_ICON);
    if (bitmap != null)
        simpleNotification.largeIcon = Bitmaps.base64(bitmap);
    if ((notification.flags & Notification.FLAG_SHOW_LIGHTS) == Notification.FLAG_SHOW_LIGHTS) {
        simpleNotification.lights = Arrays.asList(notification.ledARGB, notification.ledOnMS,
                notification.ledOffMS);
    }
    simpleNotification.localOnly = (notification.flags
            & Notification.FLAG_LOCAL_ONLY) == Notification.FLAG_LOCAL_ONLY;
    simpleNotification.number = notification.number > 0 ? notification.number : null;
    simpleNotification.ongoing = (notification.flags
            & Notification.FLAG_ONGOING_EVENT) == Notification.FLAG_ONGOING_EVENT;
    simpleNotification.onlyAlertOnce = (notification.flags
            & Notification.FLAG_ONLY_ALERT_ONCE) == Notification.FLAG_ONLY_ALERT_ONCE;
    String[] people = notification.extras.getStringArray(Notification.EXTRA_PEOPLE);
    if (people != null) {
        simpleNotification.people = Arrays.asList(people);
    }
    simpleNotification.priority = notification.priority > 0 ? notification.priority : null;
    //simpleNotification.progress;
    simpleNotification.publicVersion = notification.publicVersion;
    simpleNotification.showWhen = notification.extras.getBoolean(Notification.EXTRA_SHOW_WHEN);
    if (simpleNotification.showWhen) {
        simpleNotification.when = notification.when;
    }
    simpleNotification.smallIcon = String.valueOf(notification.extras.getInt(Notification.EXTRA_SMALL_ICON)); // TODO getResourceNameById()
    android.util.Log.d("json2notification", "simpleNotification.smallIcon" + simpleNotification.smallIcon);
    simpleNotification.sortKey = notification.getSortKey();
    simpleNotification.sound = notification.sound;
    simpleNotification.subText = notification.extras.getString(Notification.EXTRA_SUB_TEXT);
    simpleNotification.tickerText = notification.tickerText;
    simpleNotification.usesChronometer = notification.extras.getBoolean(Notification.EXTRA_SHOW_CHRONOMETER);
    simpleNotification.visibility = notification.visibility > 0 ? notification.visibility : null;
    return simpleNotification;
}