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:gcm.GcmMessageHandler.java

private void createNotification(String title, String body) {
    Context context = getBaseContext();

    int defaults = 0;
    defaults = defaults | Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE
            | Notification.DEFAULT_SOUND | Notification.FLAG_AUTO_CANCEL;

    Intent notificationIntent = new Intent(context, ConversationActivity.class);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent contentIndent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.mipmap.ic_launcher).setContentTitle(title).setContentText(body)
            .setDefaults(defaults).setStyle(new NotificationCompat.BigTextStyle().bigText(body))
            .setContentIntent(contentIndent).setAutoCancel(true);
    NotificationManager mNotificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(MESSAGE_NOTIFICATION_ID, mBuilder.build());
}

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

@SuppressWarnings("deprecation")
public static Notification createMessageNotification(Context context, int msgCount, String msgSender,
        String msg, Bitmap contactIcon, PendingIntent intent) {
    String title;//  w ww . j a v a2  s. c om
    if (msgCount == 1) {
        title = msgSender;
    } else {
        title = context.getString(R.string.unread_messages).replace("%i", String.valueOf(msgCount));
    }

    Notification notif = new Notification.Builder(context).setContentTitle(title).setContentText(msg)
            .setContentIntent(intent).setSmallIcon(R.drawable.chat_icon_over).setAutoCancel(true)
            .setDefaults(
                    Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE)
            .setWhen(System.currentTimeMillis()).setLargeIcon(contactIcon).getNotification();

    return notif;
}

From source file:com.codemobiles.util.CMNotification.java

public static void notify(final Context ctx, final int iconResID, final String remote_image_url,
        final String title, final String desc, final Class<?> receiver) {
    final Handler handler = new Handler();
    new Thread(new Runnable() {

        @Override//from  www. j a va  2  s  .c om
        public void run() {
            try {
                remote_picture = BitmapFactory
                        .decodeStream((InputStream) new URL(remote_image_url).getContent());
                // remote_picture = BitmapFactory.decodeResource(ctx.getResources(), R.drawable.ic_launcher);
            } catch (IOException e) {
                e.printStackTrace();
            }

            handler.post(new Runnable() {

                @Override
                public void run() {
                    // TODO Auto-generated method stub
                    mNotificationManager = (NotificationManager) ctx
                            .getSystemService(Context.NOTIFICATION_SERVICE);

                    Notification noti = setNormalNotification(ctx, iconResID, remote_picture, title, desc,
                            receiver);
                    // Notification noti = setBigTextStyleNotification(ctx);
                    noti.defaults |= Notification.DEFAULT_LIGHTS;
                    noti.defaults |= Notification.DEFAULT_VIBRATE;
                    noti.defaults |= Notification.DEFAULT_SOUND;
                    noti.defaults |= Notification.FLAG_AUTO_CANCEL;
                    noti.flags |= Notification.FLAG_ONLY_ALERT_ONCE;

                    final int notificationID = new Random().nextInt();
                    noti.when = System.currentTimeMillis() + 1000 * 60;
                    mNotificationManager.notify(notificationID, noti);
                }
            });

        }
    }).start();

}

From source file:es.ugr.swad.swadroid.gui.AlertNotificationFactory.java

public static NotificationCompat.Builder createAlertNotificationBuilder(Context context, String contentTitle,
        String contentText, String ticker, PendingIntent pendingIntent, int smallIcon, int largeIcon,
        boolean alertSignals, boolean autocancel, boolean ongoing, boolean onlyAlertOnce) {

    int flags = 0;

    NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(context).setAutoCancel(autocancel)
            .setSmallIcon(smallIcon)// w ww .j  a  va  2 s.  com
            .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), largeIcon))
            .setContentTitle(contentTitle).setContentText(contentText).setTicker(ticker).setOngoing(ongoing)
            .setOnlyAlertOnce(onlyAlertOnce).setWhen(System.currentTimeMillis());
    //.setLights(Color.GREEN, 500, 500);

    //Launch activity on alert click
    if (pendingIntent != null) {
        notifBuilder.setContentIntent(pendingIntent);
    }

    //Add sound, vibration and lights
    if (alertSignals) {
        if (Preferences.isNotifSoundEnabled()) {
            flags |= Notification.DEFAULT_SOUND;
        } else {
            notifBuilder.setSound(null);
        }

        if (Preferences.isNotifVibrateEnabled()) {
            flags |= Notification.DEFAULT_VIBRATE;
        }

        if (Preferences.isNotifLightsEnabled()) {
            flags |= Notification.DEFAULT_LIGHTS;
        }
    }

    notifBuilder.setDefaults(flags);

    return notifBuilder;
}

From source file:enterprayz.megatools.NotificationBuilder.java

private static void createNotification(Context context, Class activity, int id, int largeIcoRes,
        int smallIcoRes, String title, String subTitle, String ticket, boolean canCancel) {
    Bitmap largeIcon = BitmapFactory.decodeResource(context.getResources(), largeIcoRes);

    Intent intent = new Intent(context, activity);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, FLAG_ACTIVITY_NEW_TASK);
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
            .setContentText(subTitle).setContentTitle(title).setSmallIcon(smallIcoRes).setOngoing(!canCancel)
            .setTicker(ticket).setLargeIcon(largeIcon)
            .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE)
            .setContentIntent(pendingIntent);

    Notification notification = notificationBuilder.build();

    notificationManager.notify(id, notification);
}

From source file:org.hansel.myAlert.StopScheduleActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    AlarmManager am = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
    am.cancel(Util.getReminderPendingIntennt(getApplicationContext()));
    PreferenciasHancel.setAlarmStartDate(getApplicationContext(), 0);
    //ya se termino el tiempo de la programacin cancelamos alarma y salimos
    Log.v("Fin de la programacin");
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher).setContentTitle("Rastreo Finalizado")
            .setContentText("Gracias por usar Hancel");

    Notification notif = mBuilder.build();
    notif.flags = Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL;
    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notificationManager.notify(0, notif);
    finish();/*w  w w  . j  a v a  2 s . c  om*/
    return;
}

From source file:es.ugr.swad.swadroid.gui.AlertNotification.java

public static void alertNotif(Context context, int notifAlertId, String contentTitle, String contentText,
        String ticker, Intent activity) {

    //Obtain a reference to the notification service
    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager notifManager = (NotificationManager) context.getSystemService(ns);

    //Configure the alert
    int defaults = 0;

    NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(context).setAutoCancel(true)
            .setSmallIcon(R.drawable.ic_launcher_swadroid)
            .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher_swadroid))
            .setContentTitle(contentTitle).setContentText(contentText).setTicker(ticker)
            .setWhen(System.currentTimeMillis());
    //.setLights(Color.GREEN, 500, 500);

    //Launch activity on alert click
    if (activity != null) {
        PendingIntent notificationsPendingIntent = PendingIntent.getActivity(context, 0, activity,
                Intent.FLAG_ACTIVITY_NEW_TASK);
        notifBuilder.setContentIntent(notificationsPendingIntent);
    }//from ww w .  j  a v  a2  s .c o  m

    //Add sound, vibration and lights
    if (Preferences.isNotifSoundEnabled()) {
        defaults |= Notification.DEFAULT_SOUND;
    } else {
        notifBuilder.setSound(null);
    }

    if (Preferences.isNotifVibrateEnabled()) {
        defaults |= Notification.DEFAULT_VIBRATE;
    }

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

    notifBuilder.setDefaults(defaults);

    //Create alert
    Notification notif = notifBuilder.build();

    //Send alert
    notifManager.notify(notifAlertId, notif);
}

From source file:com.mattermost.gcm.GcmMessageHandler.java

private void createNotification(boolean doAlert) {
    Context context = getBaseContext();

    int defaults = 0;
    defaults = defaults | Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL;

    if (doAlert) {
        defaults = defaults | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND;
    }/*from  ww w  . j a  v a  2 s . c o m*/

    Intent notificationIntent = new Intent(context, SplashScreenActivity.class);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent contentIndent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

    PendingIntent deleteIntent = PendingIntent.getBroadcast(context, 0,
            new Intent(context, NotificationDismissReceiver.class), 0);

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

    if (channelIdToNotification.size() == 0) {
        mNotificationManager.cancel(MESSAGE_NOTIFICATION_ID);
        return;
    }

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.mipmap.ic_launcher).setGroup(GROUP_KEY_MESSAGES).setDefaults(defaults)
            .setContentIntent(contentIndent).setDeleteIntent(deleteIntent).setAutoCancel(true);

    if (channelIdToNotification.size() == 1) {
        Bundle data = channelIdToNotification.entrySet().iterator().next().getValue();
        String body = data.getString("message");
        mBuilder.setContentTitle("Mattermost").setContentText(body)
                .setStyle(new NotificationCompat.BigTextStyle().bigText(body));
    } else {
        NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle();

        String summaryTitle = String.format("Mattermost (%d)", channelIdToNotification.size());
        mBuilder.setContentTitle(summaryTitle);

        for (Bundle data : channelIdToNotification.values()) {
            style.addLine(data.getString("message"));
        }

        style.setBigContentTitle(summaryTitle);
        mBuilder.setStyle(style);
    }

    mNotificationManager.cancel(MESSAGE_NOTIFICATION_ID);
    mNotificationManager.notify(MESSAGE_NOTIFICATION_ID, mBuilder.build());
}

From source file:nu.shout.shout.chat.ChatNotifier.java

private void applySettings() {
    int defaults = 0;
    if (this.prefs.getBoolean("noti_sound", true))
        defaults |= Notification.DEFAULT_SOUND;
    if (this.prefs.getBoolean("noti_vibrate", true))
        defaults |= Notification.DEFAULT_VIBRATE;
    if (this.prefs.getBoolean("noti_light", true))
        defaults |= Notification.DEFAULT_LIGHTS;
    this.builder.setDefaults(defaults);
}

From source file:com.jsw.callcastreceiver.Call_BroadCastReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    Bundle bundle = intent.getExtras();/*from ww w . j av  a2s  .  co  m*/
    if (bundle != null) {
        String state = bundle.getString(TelephonyManager.EXTRA_STATE);
        if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
            String number = bundle.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);

            Intent newIntent = new Intent(context, Telefon_Activity.class);
            newIntent.putExtra("number", number);
            PendingIntent pending = PendingIntent.getActivity(context, CALLNOTIFICATION, newIntent,
                    PendingIntent.FLAG_ONE_SHOT);
            NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
            builder.setContentTitle("Telefon Activity");
            builder.setSmallIcon(R.mipmap.ic_launcher);
            builder.setContentText("Incoming call from: " + number);
            builder.setDefaults(Notification.DEFAULT_VIBRATE);
            builder.setDefaults(Notification.DEFAULT_LIGHTS);
            //Aadir el objeto PendingItem a la notificicacion
            builder.setContentIntent(pending);
            //Aadir la notificacion al Manager
            NotificationManager notify = (NotificationManager) context
                    .getSystemService(Context.NOTIFICATION_SERVICE);
            notify.notify(CALLNOTIFICATION, builder.build());
        }
    }
}