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:gov.wa.wsdot.android.wsdot.service.MyFirebaseMessagingService.java

private void startHighwayAlertDetailsActivity(int id, String title, String message, Map data) {

    // Create an Intent for the activity you want to start
    Intent resultIntent = new Intent(this, HighwayAlertDetailsActivity.class);
    // Create the TaskStackBuilder and add the intent, which inflates the back stack
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);

    Bundle b1 = new Bundle();
    b1.putInt("id", Integer.valueOf(data.get("alert_id").toString()));
    b1.putBoolean("refresh", true);
    b1.putBoolean("from_notification", true);
    resultIntent.putExtras(b1);//from ww w .  ja  v a  2s  .c om
    resultIntent.setAction("actionstring" + System.currentTimeMillis());
    stackBuilder.addNextIntentWithParentStack(resultIntent);

    Bundle b2 = new Bundle();

    if ((data.get("lat") != null && data.get("long") != null)) {

        b2.putDouble("lat", Double.valueOf(data.get("lat").toString()));
        b2.putDouble("long", Double.valueOf(data.get("long").toString()));
        b2.putInt("zoom", 15);

    } else {
        Log.i(TAG, "no data for bundle");
    }

    // set extras for the FerriesRouteAlertsBulletinsFragment
    stackBuilder.editIntentAt(stackBuilder.getIntentCount() - 2).putExtras(b2);

    // Get the PendingIntent containing the entire back stack
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this, ALERT_CHANNEL_ID)
                .setSmallIcon(R.drawable.ic_list_wsdot).setContentTitle(title).setContentText(message)
                .setChannelId(ALERT_CHANNEL_ID).setStyle(new NotificationCompat.BigTextStyle().bigText(message))
                .setContentIntent(resultPendingIntent)
                .setColor(ContextCompat.getColor(this, R.color.primary_default)).setAutoCancel(true)
                .setGroup(String.valueOf(System.currentTimeMillis())).setDefaults(Notification.DEFAULT_LIGHTS);
        NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
        notificationManager.notify(id, builder.build());
    } else {
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.ic_list_wsdot).setContentTitle(title).setContentText(message)
                .setStyle(new NotificationCompat.BigTextStyle().bigText(message))
                .setContentIntent(resultPendingIntent).setAutoCancel(true).setWhen(0)
                .setDefaults(Notification.DEFAULT_LIGHTS);
        NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
        notificationManager.notify(id, builder.build());
    }
}

From source file:com.mattprecious.prioritysms.receiver.AlarmReceiver.java

private void doAlarm(Context context, BaseProfile profile, String number, String message) {
    // Maintain a cpu wake lock until the AlarmActivity and AlarmService can
    // pick it up.
    AlarmAlertWakeLock.acquireCpuWakeLock(context);

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

    // Play the alarm alert and vibrate the device.
    Intent playAlarm = new Intent(Intents.ACTION_ALERT);
    playAlarm.putExtra(Intents.EXTRA_PROFILE, profile);
    context.startService(playAlarm);//from  w  w  w .  j  a v a2 s  . c o m

    Intent dismissIntent = new Intent(Intents.ACTION_DISMISS);
    dismissIntent.putExtra(Intents.EXTRA_PROFILE, profile);
    PendingIntent pendingDismiss = PendingIntent.getBroadcast(context, profile.getId(), dismissIntent, 0);

    Intent replyIntent = new Intent(Intents.ACTION_REPLY);
    replyIntent.putExtra(Intents.EXTRA_PROFILE, profile);
    PendingIntent pendingReply = PendingIntent.getBroadcast(context, profile.getId(), replyIntent, 0);

    Intent callIntent = new Intent(Intents.ACTION_CALL);
    callIntent.putExtra(Intents.EXTRA_PROFILE, profile);
    PendingIntent pendingCall = PendingIntent.getBroadcast(context, profile.getId(), callIntent, 0);

    Intent activityIntent = new Intent(context, AlarmActivity.class);
    activityIntent.setAction(String.valueOf(System.currentTimeMillis()));
    activityIntent.putExtra(Intents.EXTRA_PROFILE, profile);
    activityIntent.putExtra(Intents.EXTRA_NUMBER, number);
    activityIntent.putExtra(Intents.EXTRA_MESSAGE, message);
    activityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_USER_ACTION);
    PendingIntent pendingActivity = PendingIntent.getActivity(context, profile.getId(), activityIntent, 0);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setContentTitle(profile.getName()).setSmallIcon(R.drawable.ic_stat_alarm).setAutoCancel(false)
            .setPriority(NotificationCompat.PRIORITY_MAX).setDefaults(Notification.DEFAULT_LIGHTS)
            .addAction(android.R.drawable.ic_menu_close_clear_cancel,
                    context.getString(R.string.notif_action_dismiss), pendingDismiss)
            .addAction(android.R.drawable.ic_menu_send, context.getString(R.string.notif_action_reply),
                    pendingReply)
            .addAction(android.R.drawable.ic_menu_call, context.getString(R.string.notif_action_call),
                    pendingCall)
            .setFullScreenIntent(pendingActivity, true).setContentIntent(pendingActivity)
            .setDeleteIntent(pendingDismiss);

    Notification notif = builder.build();

    // Send the notification using the alarm id to easily identify the
    // correct notification.
    NotificationManager nm = getNotificationManager(context);
    nm.notify(profile.getId(), notif);

    // full screen intent doesn't do anything pre-honeycomb
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
        context.startActivity(activityIntent);
    }
}

From source file:dentex.youtube.downloader.utils.Utils.java

public static void setNotificationDefaults(NotificationCompat.Builder aBuilder) {
    String def = YTD.settings.getString("notification_defaults", "0");
    if (aBuilder != null) {
        if (def.equals("0")) {
            aBuilder.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE);
        }/*from   w w w . j  ava 2  s . co  m*/
        if (def.equals("1")) {
            aBuilder.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS);
        }
        if (def.equals("2")) {
            aBuilder.setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE);
        }
        if (def.equals("3")) {
            aBuilder.setDefaults(Notification.DEFAULT_ALL);
        }
        if (def.equals("4")) {
            aBuilder.setDefaults(Notification.DEFAULT_SOUND);
        }
        if (def.equals("5")) {
            aBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
        }
        if (def.equals("6")) {
            aBuilder.setDefaults(Notification.DEFAULT_LIGHTS);
        }
        if (def.equals("7")) {
            // nothing...
        }
    }
}

From source file:com.manuelmazzuola.speedtogglebluetooth.service.MonitorSpeed.java

private void changeMessage(String message) {
    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    Intent stopIntent = new Intent(this, MainActivity.class);
    stopIntent.putExtra("close", "close");
    PendingIntent stopPendingIntent = PendingIntent.getActivity(this, 0, stopIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder note = new NotificationCompat.Builder(this).setContentTitle(DEFAULT_TITLE)
            .setContentText(message).setAutoCancel(true).setContentIntent(stopPendingIntent)
            .setSmallIcon(R.drawable.ic_action_bluetooth);

    note.getNotification().flags |= Notification.FLAG_AUTO_CANCEL;

    Notification notification = note.build();
    notification.flags = Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL;

    notificationManager.notify(intentId, notification);
}

From source file:com.yek.keyboard.ChewbaccaUncaughtExceptionHandler.java

public void uncaughtException(Thread thread, Throwable ex) {
    ex.printStackTrace();// w  ww.ja va 2 s.co m
    Logger.e(TAG, "Caught an unhandled exception!!!", ex);
    boolean ignore = false;

    // https://github.com/AnySoftKeyboard/AnySoftKeyboard/issues/15
    //https://github.com/AnySoftKeyboard/AnySoftKeyboard/issues/433
    String stackTrace = Logger.getStackTrace(ex);
    if (ex instanceof NullPointerException) {
        if (stackTrace.contains(
                "android.inputmethodservice.IInputMethodSessionWrapper.executeMessage(IInputMethodSessionWrapper.java")
                || stackTrace.contains(
                        "android.inputmethodservice.IInputMethodWrapper.executeMessage(IInputMethodWrapper.java")) {
            Logger.w(TAG, "An OS bug has been adverted. Move along, there is nothing to see here.");
            ignore = true;
        }
    } else if (ex instanceof java.util.concurrent.TimeoutException) {
        if (stackTrace.contains(".finalize")) {
            Logger.w(TAG, "An OS bug has been adverted. Move along, there is nothing to see here.");
            ignore = true;
        }
    }

    if (!ignore && AnyApplication.getConfig().useChewbaccaNotifications()) {
        String appName = DeveloperUtils.getAppDetails(mApp);

        final CharSequence utcTimeDate = DateFormat.format("kk:mm:ss dd.MM.yyyy", new Date());
        final String newline = DeveloperUtils.NEW_LINE;
        String logText = "Hi. It seems that we have crashed.... Here are some details:" + newline
                + "****** UTC Time: " + utcTimeDate + newline + "****** Application name: " + appName + newline
                + "******************************" + newline + "****** Exception type: "
                + ex.getClass().getName() + newline + "****** Exception message: " + ex.getMessage() + newline
                + "****** Trace trace:" + newline + stackTrace + newline;
        logText += "******************************" + newline + "****** Device information:" + newline
                + DeveloperUtils.getSysInfo(mApp);
        if (ex instanceof OutOfMemoryError
                || (ex.getCause() != null && ex.getCause() instanceof OutOfMemoryError)) {
            logText += "******************************\n" + "****** Memory:" + newline + getMemory();
        }

        if (ex instanceof Resources.NotFoundException) {
            int resourceId = extractResourceIdFromException((Resources.NotFoundException) ex);
            logText += "******************************\n";
            if (resourceId == 0) {
                logText += "Failed to extract resource id from message\n";
            } else {
                String possibleResources = getResourcesNamesWithValue(resourceId);
                if (TextUtils.isEmpty(possibleResources)) {
                    logText += "Could not find matching resources for resource id " + resourceId
                            + ", this may happen if the resource is from an external package.\n";
                } else {
                    logText += "Possible resources for " + resourceId + ":\n";
                }

            }
            logText += "******************************\n";
        }
        logText += "******************************" + newline + "****** Log-Cat:" + newline
                + Logger.getAllLogLines();

        String crashType = ex.getClass().getSimpleName() + ": " + ex.getMessage();
        Intent notificationIntent = new Intent(mApp, SendBugReportUiActivity.class);
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        final Parcelable reportDetailsExtra = new SendBugReportUiActivity.BugReportDetails(ex, logText);
        notificationIntent.putExtra(SendBugReportUiActivity.EXTRA_KEY_BugReportDetails, reportDetailsExtra);

        PendingIntent contentIntent = PendingIntent.getActivity(mApp, 0, notificationIntent, 0);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(mApp);
        builder.setSmallIcon(
                Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB ? R.drawable.notification_error_icon
                        : R.drawable.ic_notification_error)
                .setColor(ContextCompat.getColor(mApp, R.color.notification_background_error))
                .setTicker(mApp.getText(R.string.ime_crashed_ticker))
                .setContentTitle(mApp.getText(R.string.ime_name))
                .setContentText(mApp.getText(R.string.ime_crashed_sub_text))
                .setSubText(BuildConfig.TESTING_BUILD ? crashType
                        : null/*not showing the type of crash in RELEASE mode*/)
                .setWhen(System.currentTimeMillis()).setContentIntent(contentIntent).setAutoCancel(true)
                .setOnlyAlertOnce(true).setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE);

        // notifying
        NotificationManager notificationManager = (NotificationManager) mApp
                .getSystemService(Context.NOTIFICATION_SERVICE);

        notificationManager.notify(R.id.notification_icon_app_error, builder.build());
    }
    // and sending to the OS
    if (!ignore && mOsDefaultHandler != null) {
        Logger.i(TAG, "Sending the exception to OS exception handler...");
        mOsDefaultHandler.uncaughtException(thread, ex);
    }

    Thread.yield();
    //halting the process. No need to continue now. I'm a dead duck.
    System.exit(0);
}

From source file:vn.seasoft.sachcuatui.GCMService.GCMIntentService.java

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

    Intent intent;/*from w ww.j  a  v  a2 s. com*/
    if (book == null) {
        intent = new Intent(this, MainActivity.class);
    } else {
        intent = new Intent(this, actInfoBook.class);
        intent.putExtra("idbook", book.getIdbook());
        intent.putExtra("titlebook", book.getTitle());
        intent.putExtra("authorbook", book.getAuthor());
        intent.putExtra("countview", book.getCountview());
        intent.putExtra("countdownload", book.getCountdownload());
        intent.putExtra("idcategory", book.getIdcategory());
        intent.putExtra("summary", book.getSummary());
        intent.putExtra("cover", book.getImagecover());
    }

    intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);

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

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher).setContentTitle("Sch Ca Tui")
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg);
    mBuilder.setAutoCancel(true);
    mBuilder.setContentIntent(contentIntent);
    Notification notification = mBuilder.build();
    notification.flags |= Notification.FLAG_AUTO_CANCEL;

    notification.defaults |= Notification.DEFAULT_SOUND;
    notification.defaults |= Notification.DEFAULT_LIGHTS;
    mNotificationManager.notify(NOTIFICATION_ID, notification);
}

From source file:org.android.gcm.client.GcmIntentService.java

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

    Intent intent = getPushactIntent(0);
    if (!action.isEmpty()) {
        intent.setAction(action);//from w ww. j ava 2  s .c  o m
    }
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_stat_gcm).setContentTitle(getString(R.string.notification))
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg)
            .setAutoCancel(true).setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS);

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

From source file:rp.soi.dmsd.notextingwhilewalking.DetectedActivitiesIntentService.java

public void createNotification(boolean makeHeadsUpNotification) {

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_priority_high_black_24dp).setPriority(Notification.PRIORITY_DEFAULT)
            .setCategory(Notification.CATEGORY_MESSAGE).setContentTitle("No-Texting-While-Walking")
            .setContentText("It is hazardous to be texting while walking.");

    if (makeHeadsUpNotification) {

        Intent push = new Intent(getApplication(), MainActivity.class);
        push.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
        //push.setClass(this, MainActivity.class);

        PendingIntent fullScreenPendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, push,
                PendingIntent.FLAG_CANCEL_CURRENT);
        notificationBuilder.setContentText("It is hazardous to be texting while walking.")
                .setFullScreenIntent(fullScreenPendingIntent, true);
    }//w ww .j  a v a 2s . c  om
    Notification notification = notificationBuilder.build();
    //---set the sound and lights---
    notification.defaults |= Notification.DEFAULT_SOUND;
    notification.defaults |= Notification.DEFAULT_LIGHTS;

    //---gets an instance of the NotificationManager service---
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);

    //---build the notification and issues it
    // with notification manager---
    notificationManager.notify(WEARABLE_NOTIFICATION_ID, notification);
}

From source file:ru.glesik.wifireminders.AlarmService.java

public void showReminder(String title, String text) {
    SharedPreferences sharedPrefSettings = PreferenceManager.getDefaultSharedPreferences(this);
    boolean vibrate = sharedPrefSettings.getBoolean("prefVibrate", true);
    String sound = sharedPrefSettings.getString("prefRingtone", "default");
    Uri soundURI = Uri.parse(sound);/* w w  w  .  j  a  v a2s. c  om*/
    NotificationManager mNotificationManager = (NotificationManager) this
            .getSystemService(Context.NOTIFICATION_SERVICE);
    int icon;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // Icon for Android 3.0+.
        icon = R.drawable.notify;
    } else {
        // Icon for Android 2.3 and lower.
        icon = R.drawable.notify_legacy;
    }
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon(icon)
            .setContentTitle(title).setContentText(text)
            //.setVibrate(pattern)
            .setSound(soundURI).setDefaults(
                    //                  Notification.DEFAULT_SOUND
                    //                        | Notification.DEFAULT_VIBRATE
                    Notification.DEFAULT_LIGHTS)
            .setPriority(NotificationCompat.PRIORITY_HIGH).setOnlyAlertOnce(true);
    Intent ni = new Intent(this, RemindersListActivity.class);
    ni.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent pi = PendingIntent.getActivity(this, 0, ni, 0);
    mBuilder.setContentIntent(pi);
    mBuilder.setAutoCancel(true);
    Notification notification = mBuilder.build();
    if (vibrate) {
        notification.defaults |= Notification.DEFAULT_VIBRATE;
    }
    // Displaying notification with random id, in case there will be more.
    mNotificationManager.notify((int) (Math.random() * ((999) + 1)), notification);
}

From source file:com.snappy.GCMIntentService.java

@SuppressWarnings("deprecation")
public void triggerNotification(Context context, String message, String fromName, Bundle pushExtras,
        String messageData) {/* www.  j av a  2 s .c o m*/

    if (fromName != null) {
        final NotificationManager notificationManager = (NotificationManager) getSystemService(
                NOTIFICATION_SERVICE);

        Notification notification = new Notification(R.drawable.icon_notification, message,
                System.currentTimeMillis());

        notification.number = mNotificationCounter + 1;
        mNotificationCounter = mNotificationCounter + 1;

        Intent intent = new Intent(this, SplashScreenActivity.class);
        intent.replaceExtras(pushExtras);
        intent.putExtra(Const.PUSH_INTENT, true);
        intent.setAction(Long.toString(System.currentTimeMillis()));
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_FROM_BACKGROUND
                | Intent.FLAG_ACTIVITY_TASK_ON_HOME);

        PendingIntent pendingIntent = PendingIntent.getActivity(this, notification.number, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);

        notification.setLatestEventInfo(this, context.getString(R.string.app_name), messageData, pendingIntent);

        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        notification.defaults |= Notification.DEFAULT_VIBRATE;
        notification.defaults |= Notification.DEFAULT_SOUND;
        notification.defaults |= Notification.DEFAULT_LIGHTS;
        String notificationId = Double.toString(Math.random());
        notificationManager.notify(notificationId, 0, notification);

    }

    Log.i(LOG_TAG, message);
    Log.i(LOG_TAG, fromName);

}