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.riksof.a320.c2dm.common.C2DMReceiver.java

@Override
protected void onMessage(Context contxt, Intent intent) {

    String unValidatedURL = intent.getStringExtra("payload");
    Log.w("C2DMReceiver", unValidatedURL);

    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    int icon = R.drawable.ic_launcher; // icon from resources

    CharSequence tickerText = "You got message !!!"; // ticker-text
    long when = System.currentTimeMillis(); // notification time
    Context context = getApplicationContext(); // application Context

    Intent notificationIntent = new Intent(this, PushEndpointDemo.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

    CharSequence contentTitle = "Norification Received !";

    // the next two lines initialize the Notification, using the configurations above
    Notification notification = new Notification(icon, tickerText, when);
    notification.defaults |= Notification.DEFAULT_LIGHTS;
    notification.ledARGB = 0xff00ff00;/*from ww w  .  j  a  v  a  2  s  .c o  m*/
    notification.ledOnMS = 300;
    notification.ledOffMS = 1000;
    notification.flags |= Notification.FLAG_SHOW_LIGHTS;
    notification.setLatestEventInfo(context, contentTitle, unValidatedURL, contentIntent);
    notificationManager.notify(10001, notification);

    Cache.getInstance().remove(unValidatedURL);
    FileCache fc = new FileCache(context);
    fc.clear();

    Log.w("C2DMReceiver", "finish");
}

From source file:com.asb.spandan2014.GcmIntentService.java

private void sendNotification(String msg) {
    mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

    Intent resultIntent = new Intent(this, AlertsActivity.class);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    // Adds the back stack
    stackBuilder.addParentStack(AlertsActivity.class);
    // Adds the Intent to the top of the stack
    stackBuilder.addNextIntent(resultIntent);
    // Gets a PendingIntent containing the entire back stack
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.alerts)
            .setContentTitle(getString(R.string.spandan_update))
            .setDefaults(Notification.DEFAULT_VIBRATE | Notification.FLAG_SHOW_LIGHTS
                    | Notification.FLAG_AUTO_CANCEL | Notification.DEFAULT_LIGHTS)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg);

    mBuilder.setContentIntent(resultPendingIntent);
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}

From source file:com.lugia.timetable.ReminderService.java

@Override
protected void onHandleIntent(Intent intent) {
    String action = intent.getAction();

    Log.d("ReminderService", "Handle intent : " + action);

    Bundle extra = intent.getExtras();//from  ww  w  .  j  ava  2  s .c  o  m

    String subjectCode = extra.getString(EXTRA_SUBJECT_CODE);
    String header = extra.getString(EXTRA_HEADER);
    String content = extra.getString(EXTRA_CONTENT);

    String boardcastIntent = null;

    Intent notificationIntent = new Intent();
    Uri soundUri = null;

    int notificationId;
    boolean vibrate;

    if (action.equals(ACTION_SCHEDULE_REMINDER)) {
        notificationId = SCHEDULE_NOTIFICATION_ID;

        vibrate = SettingActivity.getBoolean(ReminderService.this, SettingActivity.KEY_SCHEDULE_NOTIFY_VIBRATE,
                false);

        String soundUriStr = SettingActivity.getString(ReminderService.this,
                SettingActivity.KEY_SCHEDULE_NOTIFY_SOUND, "");

        notificationIntent.setClass(ReminderService.this, SubjectDetailActivity.class)
                .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                .putExtra(SubjectDetailActivity.EXTRA_SUBJECT_CODE, subjectCode);

        soundUri = !TextUtils.isEmpty(soundUriStr) ? Uri.parse(soundUriStr) : null;

        boardcastIntent = ReminderReceiver.ACTION_UPDATE_SCHEDULE_REMINDER;
    } else if (action.equals(ACTION_EVENT_REMINDER)) {
        long eventId = intent.getLongExtra(EXTRA_EVENT_ID, -1);

        notificationId = EVENT_NOTIFICATION_ID;

        vibrate = SettingActivity.getBoolean(ReminderService.this, SettingActivity.KEY_EVENT_NOTIFY_VIBRATE,
                false);

        String soundUriStr = SettingActivity.getString(ReminderService.this,
                SettingActivity.KEY_EVENT_NOTIFY_SOUND, "");

        notificationIntent.setClass(ReminderService.this, SubjectDetailActivity.class)
                .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK).setAction(SubjectDetailActivity.ACTION_VIEW_EVENT)
                .putExtra(SubjectDetailActivity.EXTRA_EVENT_ID, eventId)
                .putExtra(SubjectDetailActivity.EXTRA_SUBJECT_CODE, subjectCode);

        soundUri = !TextUtils.isEmpty(soundUriStr) ? Uri.parse(soundUriStr) : null;

        boardcastIntent = ReminderReceiver.ACTION_UPDATE_EVENT_REMINDER;
    } else {
        Log.e(TAG, "Unknow action!");

        return;
    }

    PendingIntent pendingIntent = PendingIntent.getActivity(ReminderService.this, 0, notificationIntent, 0);

    Notification notification = new NotificationCompat.Builder(ReminderService.this)
            .setSmallIcon(R.drawable.ic_notification_reminder).setTicker(header).setContentTitle(header)
            .setContentText(content).setContentIntent(pendingIntent).setAutoCancel(true)
            .setWhen(System.currentTimeMillis()).build();

    // always show the notification light
    notification.defaults |= Notification.DEFAULT_LIGHTS;
    notification.flags |= Notification.FLAG_SHOW_LIGHTS;

    // only vibrate when user enable it
    if (vibrate)
        notification.defaults |= Notification.DEFAULT_VIBRATE;

    // set the notification sound
    notification.sound = soundUri;

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

    manager.notify(notificationId, notification);

    // update the reminder, so it will notify user again on next schedule
    Intent broadcastIntent = new Intent(ReminderService.this, ReminderReceiver.class);
    broadcastIntent.setAction(boardcastIntent);

    sendBroadcast(broadcastIntent);
}

From source file:ws.logv.trainmonitor.GCMIntentService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 *//*  ww w. ja va  2  s. c o m*/
public static void generateTrainLateNotification(Context context, String trainId, int delay) {

    SharedPreferences pref = context.getSharedPreferences(Constants.Settings.PERF, 0);

    if (!pref.getBoolean(Constants.Settings.NOTIFICATION_ON, true))
        return;

    int icon = R.drawable.notification;
    long when = System.currentTimeMillis();
    String message = context.getString(R.string.notification_message, trainId);
    String subText = context.getString(R.string.notification_detail, String.valueOf(delay));

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

    String title = context.getString(R.string.app_name);

    Intent notificationIntent = new Intent(context, Train.class);
    notificationIntent.putExtra(Constants.IntentsExtra.Train, trainId);
    // 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, 0);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setContentText(message)
            .setContentTitle(title).setSmallIcon(icon).setWhen(when).setAutoCancel(true).setSubText(subText)
            .setContentIntent(intent);
    builder.setDefaults(
            Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND | Notification.FLAG_SHOW_LIGHTS);

    Notification notification = builder.build();

    notificationManager.notify(trainId.hashCode(), notification);
}

From source file:com.rocketsingh.biker.GCMIntentService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 *///from w  w  w. j  a va 2 s. c om
public static 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:com.survtapp.gcm.MyGcmListenerService.java

private Notification setBigPictureStyleNotification(String msg, String url, String title) {
    Bitmap remote_picture = null;//from  w w  w .  j a  v a  2s .  c  o m
    // Create the style object with BigPictureStyle subclass.
    NotificationCompat.BigPictureStyle notiStyle = new NotificationCompat.BigPictureStyle();
    notiStyle.setBigContentTitle(title);
    notiStyle.setSummaryText(msg);
    try {
        remote_picture = getBitmapFromURL(url);
    } catch (Exception e) {
        e.printStackTrace();
    }
    notiStyle.bigPicture(remote_picture);
    Intent resultIntent = new Intent(this, MainActivity.class);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(MainActivity.class);
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    return new NotificationCompat.Builder(this).setSmallIcon(R.drawable.survtapp_notification)
            .setColor(getResources().getColor(R.color.actionbar_color)).setAutoCancel(true)
            .setDefaults(
                    Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND | Notification.FLAG_SHOW_LIGHTS)
            .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
            .setContentIntent(resultPendingIntent).setContentTitle(title).setContentText(msg)
            .setStyle(notiStyle).build();
}

From source file:im.neon.util.NotificationUtils.java

/**
 * Build a pending call notification//from w ww.j a  va 2 s  . com
 * @param context the context.
 * @param roomName the room name in which the call is pending.
 * @param roomId the room Id
 * @param matrixId the matrix id
 * @param callId the call id.
 * @return the call notification.
 */
public static Notification buildPendingCallNotification(Context context, String roomName, String roomId,
        String matrixId, String callId) {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    builder.setWhen(System.currentTimeMillis());

    builder.setContentTitle(roomName);
    builder.setContentText(context.getString(R.string.call_in_progress));
    builder.setSmallIcon(R.drawable.incoming_call_notification_transparent);

    // Build the pending intent for when the notification is clicked
    Intent roomIntent = new Intent(context, VectorRoomActivity.class);
    roomIntent.putExtra(VectorRoomActivity.EXTRA_ROOM_ID, roomId);
    roomIntent.putExtra(VectorRoomActivity.EXTRA_MATRIX_ID, matrixId);
    roomIntent.putExtra(VectorRoomActivity.EXTRA_START_CALL_ID, callId);

    // Recreate the back stack
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context).addParentStack(VectorRoomActivity.class)
            .addNextIntent(roomIntent);

    // android 4.3 issue
    // use a generator for the private requestCode.
    // When using 0, the intent is not created/launched when the user taps on the notification.
    //
    PendingIntent pendingIntent = stackBuilder.getPendingIntent((new Random()).nextInt(1000),
            PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(pendingIntent);

    Notification n = builder.build();
    n.flags |= Notification.FLAG_SHOW_LIGHTS;
    n.defaults |= Notification.DEFAULT_LIGHTS;

    return n;
}

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

private void notifyMessages(XboxLiveAccount account, long[] unreadMessages, List<Long> lastUnreadList) {
    NotificationManager mgr = getNotificationManager();
    Context context = getContext();

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

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

        App.logv("Currently unread (%d): %s", lastUnreadList.size(), s);

        s = "";/* ww w  .  ja v a 2  s.com*/
        for (Object unr : unreadMessages)
            s += unr.toString() + ",";

        App.logv("New unread (%d): %s", unreadMessages.length, s);
    }

    if (unreadMessages.length > 0) {
        int unreadCount = 0;
        for (Object unread : unreadMessages) {
            if (!lastUnreadList.contains(unread))
                unreadCount++;
        }

        if (App.getConfig().logToConsole())
            App.logv("%d computed new", unreadCount);

        if (unreadCount > 0) {
            String tickerTitle;
            String tickerText;

            if (unreadMessages.length == 1) {
                tickerTitle = context.getString(R.string.new_message);
                tickerText = context.getString(R.string.notify_message_pending_f, account.getScreenName(),
                        Messages.getSender(context, unreadMessages[0]));
            } else {
                tickerTitle = context.getString(R.string.new_messages);
                tickerText = context.getString(R.string.notify_messages_pending_f, account.getScreenName(),
                        unreadMessages.length, account.getDescription());
            }

            Notification notification = new Notification(R.drawable.xbox_stat_notify_message, tickerText,
                    System.currentTimeMillis());

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

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

            notification.flags |= Notification.FLAG_AUTO_CANCEL | Notification.FLAG_SHOW_LIGHTS;

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

            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;

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

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

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

/**
 * {@inheritDoc}/*from  w  ww .j a  v  a 2  s  .c o m*/
 */
@Override
public void onReceive(final Context context, final Intent intent) {
    final SettingsDatabase db = SettingsDatabase.getInstance(context);
    final String stopCode = intent.getStringExtra(ARG_STOPCODE);
    // Make sure the alert is still active to remain relevant.
    if (!db.isActiveProximityAlert(stopCode))
        return;

    final String stopName = BusStopDatabase.getInstance(context).getNameForBusStop(stopCode);

    final NotificationManager notMan = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    final LocationManager locMan = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);

    // Delete the alert from the database.
    db.deleteAllAlertsOfType(SettingsDatabase.ALERTS_TYPE_PROXIMITY);

    // Make sure the LocationManager no longer checks for this proximity.
    final PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, 0);
    locMan.removeProximityAlert(pi);

    final String title = context.getString(R.string.proxreceiver_notification_title, stopName);
    final String summary = context.getString(R.string.proxreceiver_notification_summary,
            intent.getIntExtra(ARG_DISTANCE, 0), stopName);
    final String ticker = context.getString(R.string.proxreceiver_notification_ticker, stopName);

    final SharedPreferences sp = context.getSharedPreferences(PreferencesActivity.PREF_FILE, 0);

    // Create the notification.
    final NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(context);
    notifBuilder.setAutoCancel(true);
    notifBuilder.setSmallIcon(R.drawable.ic_status_bus);
    notifBuilder.setTicker(ticker);
    notifBuilder.setContentTitle(title);
    notifBuilder.setContentText(summary);
    // Support for Jelly Bean notifications.
    notifBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(summary));

    final Intent launchIntent;
    if (GenericUtils.isGoogleMapsAvailable(context)) {
        // The Intent which launches the bus stop map at the selected stop.
        launchIntent = new Intent(context, BusStopMapActivity.class);
        launchIntent.putExtra(BusStopMapActivity.ARG_STOPCODE, stopCode);
    } else {
        launchIntent = new Intent(context, BusStopDetailsActivity.class);
        launchIntent.putExtra(BusStopDetailsActivity.ARG_STOPCODE, stopCode);
    }

    notifBuilder
            .setContentIntent(PendingIntent.getActivity(context, 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 to the UI.
    notMan.notify(ALERT_ID, n);
}

From source file:ca.rmen.android.networkmonitor.app.service.NetMonNotification.java

/**
 * Shows a notification with the given ticker text and content text. The icon is a warning icon, and the notification title is the app name. Tapping on the
 * notification opens the given activity.
 *///ww w  .  ja va2s . c o  m
private static void showNotification(Context context, int notificationId, int tickerTextId, int contentTextId,
        Class<?> activityClass) {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    builder.setSmallIcon(R.drawable.ic_stat_warning);
    builder.setAutoCancel(true);
    builder.setTicker(context.getString(tickerTextId));
    builder.setContentTitle(context.getString(R.string.app_name));
    builder.setContentText(context.getString(contentTextId));
    builder.setAutoCancel(false);
    Uri uri = NetMonPreferences.getInstance(context).getNotificationSoundUri();
    builder.setSound(uri);
    builder.setContentIntent(PendingIntent.getActivity(context, 0, new Intent(context, activityClass),
            PendingIntent.FLAG_UPDATE_CURRENT));
    Notification notification = builder.build();
    notification.flags |= Notification.FLAG_SHOW_LIGHTS | Notification.FLAG_ONLY_ALERT_ONCE;
    notification.ledARGB = 0xFFffff00;
    notification.ledOnMS = 300;
    notification.ledOffMS = 2000;
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(notificationId, notification);
}