Example usage for android.app Notification DEFAULT_LIGHTS

List of usage examples for android.app Notification DEFAULT_LIGHTS

Introduction

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

Prototype

int DEFAULT_LIGHTS

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

Click Source Link

Document

Use the default notification lights.

Usage

From source file:francesco.workspace.homeapp.GcmIntentService.java

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

    if (extras.containsKey("notification_type")) {
        NotificationCompat.Builder build = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.ic_iconphone).setContentTitle("TapEvent - New Group!")
                .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setAutoCancel(true)
                .setContentText(msg).setLights(Color.BLUE, 300, 100).setDefaults(Notification.DEFAULT_VIBRATE);

        mNotificationManager.notify(NOTIFICATION_ID, build.build());

        return;/* www  .j a v a2s. c o  m*/
    }

    Intent intent = new Intent(this, Event_details_invitation.class);
    Event_App ev = new Event_App(extras.getString("event_key"), extras.getString("event_name"),
            extras.getString("event_date"), extras.getString("event_hour"), extras.getString("event_user"),
            extras.getString("event_address"), extras.getString("event_location"),
            extras.getString("event_description"));

    ev.setState("false");
    intent.putExtra("singleEvent", ev);

    Intent intent_accept = new Intent();
    Intent intent_refuse = new Intent();

    intent_accept.putExtra("singleEvent", ev);
    intent_refuse.putExtra("singleEvent", ev);
    intent_accept.setAction(ACCEPT_INTENT);
    intent_refuse.setAction(REFUSE_INTENT);

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_iconphone).setContentTitle("TapEvent - New Invitation!")
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setAutoCancel(true)
            .setContentText(msg)
            .addAction(R.drawable.ok_48_blue, "Accept",
                    PendingIntent.getBroadcast(this, 1234, intent_accept, PendingIntent.FLAG_CANCEL_CURRENT))
            .addAction(R.drawable.delete_64_red, "Refuse",
                    PendingIntent.getBroadcast(this, 1234, intent_refuse, PendingIntent.FLAG_CANCEL_CURRENT))
            .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE);

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

From source file:com.rickendirk.rsgwijzigingen.ZoekService.java

private void sendNotification(Wijzigingen wijzigingen) {
    boolean isFoutMelding = wijzigingen.isFoutmelding();
    boolean isVerbindFout;
    boolean isNieuw; //Tot tegendeel bewezen is
    if (isFoutMelding) {
        isVerbindFout = wijzigingen.isVerbindfout();
        isNieuw = false;//ww w  . j a v a 2s.  c  om
    } else {
        isVerbindFout = false;
        isNieuw = wijzigingen.isNieuw(this);
    }
    if (!isFoutMelding) {
        wijzigingen.saveToSP(this);
    }
    if (!isFoutMelding && !isNieuw) {
        Log.i(TAG, "Geen nieuwe wijzigingen, geen notificatie");
        return;
    }
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_rsg_notific).setContentTitle("Roosterwijzigingen")
            .setColor(getResources().getColor(R.color.lighter_blue))
            .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS);
    if (isFoutMelding) {
        if (isVerbindFout) {
            Log.i(TAG, "Er was geen internetverbinding bij het zoeken");
            boolean moetHerhalen = PreferenceManager.getDefaultSharedPreferences(this)
                    .getBoolean("pref_auto_herhaal_geenInternet", false);
            if (moetHerhalen) {
                setAlarmIn20Min();
                Log.i(TAG, "Zal ivm geen internet in 20 minuten opnieuw zoeken");
                return;
            } else {
                builder.setContentText("Er was geen internetverbinding. Probeer het handmatig opnieuw");
            }
        } else {
            builder.setContentText("Er was een fout. Probeer het handmatig opnieuw");
        }
    } else {
        boolean zijnWijzigingen = wijzigingen.zijnWijzigingen;
        ArrayList<String> wijzigingenList = wijzigingen.getWijzigingen();
        addPossibleMessage(wijzigingen, wijzigingenList);
        if (zijnWijzigingen) {
            if (wijzigingenList.size() == 1) {
                builder.setContentText(wijzigingenList.get(0));
            } else {
                builder.setContentText("Er zijn " + wijzigingenList.size() + " wijzigingen!");
                NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
                inboxStyle.setBigContentTitle("De roosterwijzigingen zijn:");
                for (int i = 0; i < wijzigingenList.size(); i++) {
                    inboxStyle.addLine(wijzigingenList.get(i));
                }
                builder.setStyle(inboxStyle);
            }
        } else {
            boolean alleenBijWijziging = PreferenceManager.getDefaultSharedPreferences(this)
                    .getBoolean("pref_auto_zoek_alleenBijWijziging", true);
            if (!alleenBijWijziging) {
                //Dus ook bij geen-wijzigingen
                builder.setContentText("Er zijn geen roosterwijzigingen");
            } else
                return;
        }
    }
    Intent resultIntent = new Intent(this, MainActivity.class);
    resultIntent.putExtra("isVanNotificatie", true);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(MainActivity.class);
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_CANCEL_CURRENT);
    builder.setContentIntent(pendingIntent);

    NotificationManagerCompat notifManager = NotificationManagerCompat.from(this);
    notifManager.notify(notifID, builder.build());
    vibrate();
    Log.i(TAG, "Nieuwe notificatie gemaakt");
}

From source file:eu.inmite.apps.smsjizdenka.util.NotificationUtil.java

private static void fireNotification(Context c, int notificationId, PendingIntent contentIntent, String title,
        String text, List<String> rows, String summary, String ticker, int smallIcon, int largeIcon,
        List<Action> actions, boolean keepNotification) {
    int defaults = Notification.DEFAULT_LIGHTS;
    if (Preferences.getBoolean(c, Preferences.NOTIFICATION_VIBRATE, true)) {
        defaults |= Notification.DEFAULT_VIBRATE;
    }/*from w  w  w .j a  v a2  s  .  c  o m*/

    NotificationCompat.Builder builder = new NotificationCompat.Builder(c).setContentTitle(title)
            .setSmallIcon(smallIcon).setLargeIcon(BitmapFactory.decodeResource(c.getResources(), largeIcon))
            .setTicker(ticker).setContentText(text).setLocalOnly(true).setContentIntent(contentIntent)
            .setWhen(System.currentTimeMillis()).setAutoCancel(!keepNotification).setDefaults(defaults);

    String soundUri = Preferences.getString(c, Preferences.NOTIFICATION_RINGTONE, null);
    if (!TextUtils.isEmpty(soundUri)) {
        builder.setSound(Uri.parse(soundUri));
    }

    if (actions != null) {
        for (Action action : actions) {
            builder.addAction(action.drawable, c.getString(action.text), action.intent);
        }
    }

    Notification notification;
    if (rows == null) {
        notification = builder.build();
    } else {
        NotificationCompat.InboxStyle styled = new NotificationCompat.InboxStyle(builder);
        for (String row : rows) {
            styled.addLine(row);
        }
        styled.setSummaryText(summary);
        notification = styled.build();
    }

    NotificationManager nm = (NotificationManager) c.getSystemService(Context.NOTIFICATION_SERVICE);
    if (nm == null) {
        DebugLog.e("Cannot obtain notification manager");
        return;
    }

    nm.notify(notificationId, notification);
}

From source file:com.better.alarm.presenter.alert.AlarmAlertReceiver.java

private void onAlert(Alarm alarm) {
    int id = alarm.getId();

    /* Close dialogs and window shade */
    Intent closeDialogs = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
    mContext.sendBroadcast(closeDialogs);

    // Decide which activity to start based on the state of the
    // keyguard - is the screen locked or not.
    Class<? extends AlarmAlertFullScreen> c = AlarmAlert.class;
    KeyguardManager km = (KeyguardManager) mContext.getSystemService(Context.KEYGUARD_SERVICE);
    if (km.inKeyguardRestrictedInputMode()) {
        // Use the full screen activity to unlock the screen.
        c = AlarmAlertFullScreen.class;
    }//from  w  ww . j a v  a2s  . c  o m

    // Trigger a notification that, when clicked, will show the alarm
    // alert dialog. No need to check for fullscreen since this will always
    // be launched from a user action.
    Intent notify = new Intent(mContext, c);
    notify.putExtra(Intents.EXTRA_ID, id);
    PendingIntent pendingNotify = PendingIntent.getActivity(mContext, id, notify, 0);
    PendingIntent pendingSnooze = PresentationToModelIntents.createPendingIntent(mContext,
            PresentationToModelIntents.ACTION_REQUEST_SNOOZE, id);
    PendingIntent pendingDismiss = PresentationToModelIntents.createPendingIntent(mContext,
            PresentationToModelIntents.ACTION_REQUEST_DISMISS, id);

    //@formatter:off
    Notification status = new NotificationCompat.Builder(mContext)
            .setContentTitle(alarm.getLabelOrDefault(mContext))
            .setContentText(mContext.getString(R.string.alarm_notify_text))
            .setSmallIcon(R.drawable.stat_notify_alarm)
            // setFullScreenIntent to show the user AlarmAlert dialog at the same time 
            // when the Notification Bar was created.
            .setFullScreenIntent(pendingNotify, true)
            // setContentIntent to show the user AlarmAlert dialog  
            // when he will click on the Notification Bar.
            .setContentIntent(pendingNotify).setOngoing(true)
            .addAction(R.drawable.ic_action_snooze, mContext.getString(R.string.alarm_alert_snooze_text),
                    pendingSnooze)
            .addAction(R.drawable.ic_action_dismiss, mContext.getString(R.string.alarm_alert_dismiss_text),
                    pendingDismiss)
            .setDefaults(Notification.DEFAULT_LIGHTS).build();
    //@formatter:on

    // Send the notification using the alarm id to easily identify the
    // correct notification.
    nm.notify(id, status);
}

From source file:com.androzic.plugin.tracker.SMSReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    String Sender = "";
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

    Log.e(TAG, "SMS received");

    Bundle extras = intent.getExtras();//from w  w w . ja v a 2  s. c om
    if (extras == null)
        return;

    StringBuilder messageBuilder = new StringBuilder();
    Object[] pdus = (Object[]) extras.get("pdus");
    for (int i = 0; i < pdus.length; i++) {
        SmsMessage msg = SmsMessage.createFromPdu((byte[]) pdus[i]);
        String text = msg.getMessageBody();
        Sender = msg.getDisplayOriginatingAddress();
        Log.w(TAG, "Sender: " + Sender);
        if (text == null)
            continue;
        messageBuilder.append(text);
    }

    String text = messageBuilder.toString();
    boolean flexMode = prefs.getBoolean(context.getString(R.string.pref_tracker_use_flex_mode),
            context.getResources().getBoolean(R.bool.def_flex_mode));

    Log.i(TAG, "SMS: " + text);
    Tracker tracker = new Tracker();
    if (!parseXexunTK102(text, tracker) && !parseJointechJT600(text, tracker)
            && !parseTK102Clone1(text, tracker) && !(parseFlexMode(text, tracker) && flexMode))
        return;

    if (tracker.message != null) {
        tracker.message = tracker.message.trim();
        if ("".equals(tracker.message))
            tracker.message = null;
    }

    tracker.sender = Sender;

    if (!"".equals(tracker.sender)) {
        // Save tracker data
        TrackerDataAccess dataAccess = new TrackerDataAccess(context);
        dataAccess.updateTracker(tracker);

        try {
            Application application = Application.getApplication();
            tracker = dataAccess.getTracker(tracker.sender);//get  latest positon of tracker

            application.sendTrackerOnMap(dataAccess, tracker);
        } catch (RemoteException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        dataAccess.close();

        context.sendBroadcast(new Intent(Application.TRACKER_DATE_RECEIVED_BROADCAST));

        // Show notification
        boolean notifications = prefs.getBoolean(context.getString(R.string.pref_tracker_notifications),
                context.getResources().getBoolean(R.bool.def_notifications));
        if (notifications) {
            Intent i = new Intent("com.androzic.COORDINATES_RECEIVED");
            i.putExtra("title", tracker.message != null ? tracker.message : tracker.name);
            i.putExtra("sender", tracker.name);
            i.putExtra("origin", context.getApplicationContext().getPackageName());
            i.putExtra("lat", tracker.latitude);
            i.putExtra("lon", tracker.longitude);

            String msg = context.getString(R.string.notif_text, tracker.name);
            NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
            builder.setContentTitle(context.getString(R.string.app_name));
            if (tracker.message != null)
                builder.setContentText(tracker.name + ": " + tracker.message);
            else
                builder.setContentText(msg);
            PendingIntent contentIntent = PendingIntent.getBroadcast(context, (int) tracker._id, i,
                    PendingIntent.FLAG_ONE_SHOT);
            builder.setContentIntent(contentIntent);
            builder.setSmallIcon(R.drawable.ic_stat_tracker);
            builder.setTicker(msg);
            builder.setWhen(tracker.time);
            int defaults = Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND;
            boolean vibrate = prefs.getBoolean(context.getString(R.string.pref_tracker_vibrate),
                    context.getResources().getBoolean(R.bool.def_vibrate));
            if (vibrate)
                defaults |= Notification.DEFAULT_VIBRATE;
            builder.setDefaults(defaults);
            builder.setAutoCancel(true);
            Notification notification = builder.build();
            NotificationManager notificationManager = (NotificationManager) context
                    .getSystemService(Context.NOTIFICATION_SERVICE);
            notificationManager.notify((int) tracker._id, notification);
        }

        // Conceal SMS
        boolean concealsms = prefs.getBoolean(context.getString(R.string.pref_tracker_concealsms),
                context.getResources().getBoolean(R.bool.def_concealsms));
        if (concealsms)
            abortBroadcast();
    }
}

From source file:edu.oakland.cse480.GCMIntentService.java

public void sendCustNotification(String incomingMsg) {
    Log.i("incomingMsg = ", "" + incomingMsg);
    int msgCode;// w  w w.j  av a 2s  . co m
    try {
        msgCode = Character.getNumericValue(incomingMsg.charAt(0));
    } catch (Exception e) {
        msgCode = 0;
    }
    String msg;
    //String[] separated = incomingMsg.split("|");
    //separated[0] = separated[0]; //discard
    //separated[1] = separated[1] + ""; 
    //separated[2] = separated[2] + ""; //Additional message with "" to negate a null

    boolean showNotification = true;

    Intent intent;

    switch (msgCode) {
    case 1:
        msg = "A new player joined the game";
        intent = new Intent("UpdateGameLobby");
        intent.putExtra("GAMESTARTED", false);
        this.sendBroadcast(intent);
        break;
    case 2:
        msg = "The game has started";
        intent = new Intent("UpdateGameLobby");
        intent.putExtra("GAMESTARTED", true);
        this.sendBroadcast(intent);
        break;
    case 3:
        msg = "It is your turn to bet";
        intent = new Intent("UpdateGamePlay");
        this.sendBroadcast(intent);
        //Stuff
        break;
    case 4:
        msg = "Flop goes";
        break;
    case 5:
        msg = "A card has been dealt";
        //Stuff
        break;
    case 6:
        msg = "The river card, has been dealt";
        //Stuff
        break;
    case 7:
        msg = "Hand is over. Winner was " + incomingMsg.substring(1);
        intent = new Intent("UpdateGamePlay");
        intent.putExtra("WINNER", "Winner of last hand: " + incomingMsg.substring(1));
        this.sendBroadcast(intent);
        //Stuff
        break;
    case 8:
        msg = "Game is over. Winner was " + incomingMsg.substring(1);
        intent = new Intent("UpdateGamePlay");
        intent.putExtra("WINNER", "Winner of Game: " + incomingMsg.substring(1));
        this.sendBroadcast(intent);
        //Stuff
        break;
    default:
        msg = "Switch case isn't working";
        showNotification = false;
        //Some default stuff
        break;
    }

    if (showNotification) {
        mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

        Intent newIntent = new Intent(this, Gameplay.class);
        newIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, newIntent, 0);

        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.ic_launcher).setContentTitle("Poker Notification")
                .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg);

        mBuilder.setContentIntent(contentIntent);
        Notification notification = mBuilder.build();
        notification.defaults |= Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND
                | Notification.DEFAULT_VIBRATE;
        notification.flags |= Notification.FLAG_AUTO_CANCEL | Notification.FLAG_SHOW_LIGHTS;

        mNotificationManager.notify(NOTIFICATION_ID, notification);

    }
}

From source file:com.etime.ETimeActivity.java

/**
 * Notify the user with the message "message". Notification is set to
 * on-going, on-going is needed to tell android not to kill the app.
 * The phone with vibrate, and light up on notification. If the message
 * is the exact same message as the last message notified then the
 * notification is not set again.//from  ww w.j  ava 2s . co  m
 * @param message  Message to notify user with
 */
protected void notify(String message) {
    if (message.equalsIgnoreCase(lastNotificationMessage)) {
        return;
    } else {
        lastNotificationMessage = message;
    }

    int icon = R.drawable.icon;
    long when = System.currentTimeMillis();
    Context context = getApplicationContext();
    CharSequence contentTitle = "ETime";
    Intent notificationIntent = new Intent(this, ETimeActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

    mManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification(icon, message, when);
    notification.flags |= Notification.DEFAULT_LIGHTS;
    notification.flags |= Notification.FLAG_ONGOING_EVENT;
    notification.setLatestEventInfo(context, contentTitle, message, contentIntent);

    mManager.notify("ETime", APP_ID, notification);
}

From source file:se.erichansander.retrotimer.RetroTimer.java

/**
 * Sets an alarm at absolute time alarmTime (in millis from epoch)
 *//*from  w  w w  .  ja va 2s .c  o m*/
public static void setAlarmAt(Context context, long alarmTime) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor ed = prefs.edit();
    ed.putLong(RetroTimer.PREF_ALARM_TIME, alarmTime);
    ed.putBoolean(RetroTimer.PREF_ALARM_SET, true);
    ed.commit();

    Intent intent = new Intent(RetroTimer.ALARM_TRIGGER_ACTION);
    intent.putExtra(RetroTimer.ALARM_TIME_EXTRA, alarmTime);
    PendingIntent sender = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);

    /*
     * Activate alarm in AlarmManager. Since the API for activating the
     * alarm changed in KitKat, we need to treat the two versions
     * differently, and since "Dalvik in Android 1.x was very conservative
     * and would crash if you try to load a class that contains a reference
     * that it cannot resolve" we have to put it in a separate class...
     * 
     * See
     * http://stackoverflow.com/questions/13444255/could-not-find-method-
     * from-the-newer-api-with-using-targetapi-annotation
     */
    AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        am.set(AlarmManager.RTC_WAKEUP, alarmTime, sender);
    } else {
        AlarmManagerKitKat.set(am, alarmTime, sender);
    }

    // Trigger a notification that, when clicked, will open TimerSet
    Intent viewAlarm = new Intent(context, TimerSet.class);
    viewAlarm.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent pendingNotify = PendingIntent.getActivity(context, 0, viewAlarm, 0);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setContentIntent(pendingNotify).setDefaults(Notification.DEFAULT_LIGHTS).setOngoing(true)
            .setSmallIcon(R.drawable.ic_stat_alarm_set)
            .setContentTitle(context.getString(R.string.notify_set_label)).setContentText(context
                    .getString(R.string.notify_set_text, DateFormat.getTimeFormat(context).format(alarmTime)));

    /*
     * Send the notification using the alarm id to easily identify the
     * correct notification.
     */
    NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    nm.notify(RetroTimer.NOTIF_SET_ID, mBuilder.build());
}

From source file:com.piggate.sdk.Piggate.java

public void postNotification(String title, String msg, Class myClass, int resource, Bundle extras,
        Boolean force) {/*from w w  w.ja v a2 s.  co m*/
    if (!getApplicationContext().getPackageName()
            .equalsIgnoreCase(((ActivityManager) getApplicationContext()
                    .getSystemService(getApplicationContext().ACTIVITY_SERVICE)).getRunningAppProcesses()
                            .get(0).processName)
            || force) {

        Intent notifyIntent = new Intent(_context, myClass);
        if (extras != null)
            notifyIntent.putExtras(extras);
        notifyIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

        PendingIntent pendingIntent = PendingIntent.getActivities(_context, 0, new Intent[] { notifyIntent },
                PendingIntent.FLAG_UPDATE_CURRENT);
        Notification notification = new Notification.Builder(_context).setSmallIcon(resource)
                .setContentTitle(title).setContentText(msg).setAutoCancel(true).setContentIntent(pendingIntent)
                .build();
        notification.defaults |= Notification.DEFAULT_SOUND;
        notification.defaults |= Notification.DEFAULT_LIGHTS;
        notificationManager.notify(123, notification);
    }
}

From source file:com.ta.truckmap.gpstracking.GcmIntentService.java

@SuppressWarnings("deprecation")
private Notification createNotificationConstraints(PendingIntent contentIntent, int type) {
    Notification notification = new Notification(R.drawable.appicon, TAG, System.currentTimeMillis());
    notification.setLatestEventInfo(this, getResources().getString(R.string.app_name), myMsg, contentIntent);
    notification.defaults |= Notification.DEFAULT_SOUND;
    long[] vibrate = { 0, 100, 200, 300 };
    notification.vibrate = vibrate;/*ww w  . j av a 2  s.  c om*/
    notification.defaults |= Notification.DEFAULT_LIGHTS;
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    return notification;
}