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:com.BeatYourRecord.AssignmentSyncService.java

public void sendNotification(String ytdDomain, String assignmentId) {
    int notificationId = 1;

    Intent assignmentIntent = new Intent(this, DetailsActivity.class);
    assignmentIntent.putExtra(DbHelper.YTD_DOMAIN, ytdDomain);
    assignmentIntent.putExtra(DbHelper.ASSIGNMENT_ID, assignmentId);
    assignmentIntent.putExtra("notificationId", notificationId);

    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, assignmentIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    Notification n = new Notification(R.drawable.icon, "Update from YouTube Direct",
            System.currentTimeMillis());
    n.setLatestEventInfo(getApplicationContext(), "Update from YouTube Direct",
            "For " + SettingActivity.getYtdDomains(this).get(this.ytdDomain), pendingIntent);
    n.defaults |= Notification.DEFAULT_LIGHTS;
    nm.notify(notificationId, n);/*from   w w w.  jav  a 2 s.  c  o  m*/
}

From source file:com.jtechme.apphub.privileged.install.InstallExtensionDialogActivity.java

public static void runFirstTime(final Context context) {
    // don't do a "real" root access, just look up if "su" is present and has a version!
    // a real check would annoy the user
    AsyncTask<Void, Void, Boolean> checkRoot = new AsyncTask<Void, Void, Boolean>() {

        @Override//from  w  w w  . j  a v a  2  s. c o  m
        protected Boolean doInBackground(Void... params) {
            return Shell.SU.version(true) != null;
        }

        @Override
        protected void onPostExecute(Boolean probablyRoot) {
            super.onPostExecute(probablyRoot);

            // TODO: remove false condition once the install into system
            // process is stable - #294, #346, #347, #348
            if (false && probablyRoot) {
                // looks like we have root, at least su has a version number and is present

                Intent installIntent = new Intent(context, InstallExtensionDialogActivity.class);
                installIntent.setAction(InstallExtensionDialogActivity.ACTION_FIRST_TIME);
                installIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, installIntent,
                        PendingIntent.FLAG_UPDATE_CURRENT);

                NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
                        .setContentIntent(resultPendingIntent).setSmallIcon(R.drawable.ic_stat_notify)
                        .setContentTitle(context.getString(R.string.system_install_first_time_notification))
                        .setContentText(context
                                .getString(R.string.system_install_first_time_notification_message_short))
                        .setDefaults(Notification.DEFAULT_LIGHTS).setAutoCancel(true)
                        /*
                         * Sets the big view "big text" style and supplies the
                         * text (the user's reminder message) that will be displayed
                         * in the detail area of the expanded notification.
                         * These calls are ignored by the support library for
                         * pre-4.1 devices.
                         */
                        .setStyle(new NotificationCompat.BigTextStyle().bigText(
                                context.getString(R.string.system_install_first_time_notification_message)));

                NotificationManager nm = (NotificationManager) context
                        .getSystemService(Context.NOTIFICATION_SERVICE);
                nm.notify(42, builder.build());
            }
        }
    };
    checkRoot.execute();
}

From source file:org.fdroid.fdroid.privileged.install.InstallExtensionDialogActivity.java

private static void runFirstTime(final Context context) {
    // don't do a "real" root access, just look up if "su" is present and has a version!
    // a real check would annoy the user
    AsyncTask<Void, Void, Boolean> checkRoot = new AsyncTask<Void, Void, Boolean>() {

        @Override//  w w  w .ja va 2 s  .c  om
        protected Boolean doInBackground(Void... params) {
            return Shell.SU.version(true) != null;
        }

        @Override
        protected void onPostExecute(Boolean probablyRoot) {
            super.onPostExecute(probablyRoot);

            // TODO: remove false condition once the install into system
            // process is stable - #294, #346, #347, #348
            if (false && probablyRoot) {
                // looks like we have root, at least su has a version number and is present

                Intent installIntent = new Intent(context, InstallExtensionDialogActivity.class);
                installIntent.setAction(InstallExtensionDialogActivity.ACTION_FIRST_TIME);
                installIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, installIntent,
                        PendingIntent.FLAG_UPDATE_CURRENT);

                NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
                        .setContentIntent(resultPendingIntent).setSmallIcon(R.drawable.ic_stat_notify)
                        .setContentTitle(context.getString(R.string.system_install_first_time_notification))
                        .setContentText(context
                                .getString(R.string.system_install_first_time_notification_message_short))
                        .setDefaults(Notification.DEFAULT_LIGHTS).setAutoCancel(true)
                        /*
                         * Sets the big view "big text" style and supplies the
                         * text (the user's reminder message) that will be displayed
                         * in the detail area of the expanded notification.
                         * These calls are ignored by the support library for
                         * pre-4.1 devices.
                         */
                        .setStyle(new NotificationCompat.BigTextStyle().bigText(
                                context.getString(R.string.system_install_first_time_notification_message)));

                NotificationManager nm = (NotificationManager) context
                        .getSystemService(Context.NOTIFICATION_SERVICE);
                nm.notify(42, builder.build());
            }
        }
    };
    checkRoot.execute();
}

From source file:jp.co.ipublishing.esnavi.impl.gcm.GcmIntentService.java

/**
 * Notification??/* w ww.jav  a2s  . co m*/
 *
 * @param alert 
 */
private void sendNotification(@NonNull Alert alert) {
    final NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    final Intent resultIntent = new Intent(this, MapActivity.class)
            .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    final PendingIntent contentIntent = PendingIntent.getActivity(this, 1, resultIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    final Notification.Builder builder = new Notification.Builder(this).setWhen(System.currentTimeMillis())
            .setContentIntent(contentIntent)
            .setDefaults(
                    Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_LIGHTS)
            .setAutoCancel(true).setTicker(alert.getHeadlineBody()).setContentText(alert.getHeadlineBody());

    onPreSendNotification(builder, alert);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        notificationManager.notify(NOTIFICATION_ID, builder.build());
    } else {
        notificationManager.notify(NOTIFICATION_ID, builder.getNotification());
    }
}

From source file:com.android.marrowbone.anysoftboard.ChewbaccaUncaughtExceptionHandler.java

public void uncaughtException(Thread thread, Throwable ex) {
    Log.e(TAG, "Caught an unhandled exception!!! ", ex);
    boolean ignore = false;

    // https://github.com/AnySoftKeyboard/AnySoftKeyboard/issues/15
    String stackTrace = Log.getStackTrace(ex);
    if (ex instanceof NullPointerException && stackTrace != null && stackTrace.contains(
            "android.inputmethodservice.IInputMethodSessionWrapper.executeMessage(IInputMethodSessionWrapper.java")) {
        // https://github.com/AnySoftKeyboard/AnySoftKeyboard/issues/15
        Log.w(TAG, "An OS bug has been adverted. Move along, there is nothing to see here.");
        ignore = true;//from www .  j  a v a  2  s  . c o m
    }

    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();
        if (ex instanceof OutOfMemoryError
                || (ex.getCause() != null && ex.getCause() instanceof OutOfMemoryError)) {
            logText += "******************************\n" + "****** Memory:" + newline + getMemory();
        }
        logText += "******************************" + newline + "****** Log-Cat:" + newline
                + Log.getAllLogLines();

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

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

        NotificationCompat.Builder builder = new NotificationCompat.Builder(mApp);
        builder.setSmallIcon(R.drawable.notification_error_icon)
                .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.DEBUG ? 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(1, builder.build());
    }
    // and sending to the OS
    if (!ignore && mOsDefaultHandler != null) {
        Log.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:com.manuelmazzuola.speedtogglebluetooth.service.MonitorSpeed.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    running = Boolean.TRUE;/*from   w  ww. j ava 2  s .c  om*/

    lm = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
    provider = lm.NETWORK_PROVIDER;
    oldLocation = lm.getLastKnownLocation(provider);

    IntentFilter filters = new IntentFilter();
    // When to turn off bluetooth
    filters.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED);
    // When hold bluetooth on
    filters.addAction(BluetoothDevice.ACTION_ACL_CONNECTED);
    // When user directly turn on or off bluetooth
    filters.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);

    registerReceiver(bluetoothListener, filters);
    lm.requestLocationUpdates(provider, 45 * 1000, 0f, this);

    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(getApplicationContext())
            .setContentTitle(DEFAULT_TITLE).setContentText(DEFAULT_MESSAGE)
            .setDefaults(Notification.DEFAULT_VIBRATE).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;

    startForeground(intentId, note.build());

    return START_NOT_STICKY;
}

From source file:org.zywx.wbpalmstar.platform.push.PushRecieveMsgReceiver.java

private void buildPushNotification(Context context, Intent intent, PushDataInfo dataInfo) {
    String title = dataInfo.getTitle();
    String body = dataInfo.getAlert();
    String message = dataInfo.getPushDataString();
    Builder builder = new Builder(context);
    builder.setAutoCancel(true);/*from w w w .j  a v  a 2 s.  c  o m*/
    builder.setContentTitle(title); // 
    builder.setContentText(body); // 
    builder.setTicker(body); // ??

    String[] remindType = dataInfo.getRemindType();
    if (remindType != null) {
        if (remindType.length == 3) {
            builder.setDefaults(Notification.DEFAULT_ALL);
        } else {
            int defaults = 0;
            for (int i = 0; i < remindType.length; i++) {
                if ("sound".equalsIgnoreCase(remindType[i])) {
                    defaults = Notification.DEFAULT_SOUND;
                    continue;
                }
                if ("shake".equalsIgnoreCase(remindType[i])) {
                    defaults = defaults | Notification.DEFAULT_VIBRATE;
                    continue;
                }
                if ("breathe".equalsIgnoreCase(remindType[i])) {
                    defaults = defaults | Notification.DEFAULT_LIGHTS;
                    continue;
                }
            }
            builder.setDefaults(defaults);
        }
    }

    Resources res = context.getResources();
    int icon = res.getIdentifier("icon", "drawable", intent.getPackage());
    builder.setSmallIcon(icon);
    builder.setWhen(System.currentTimeMillis()); // 

    String iconUrl = dataInfo.getIconUrl();
    boolean isDefaultIcon = !TextUtils.isEmpty(iconUrl) && "default".equalsIgnoreCase(iconUrl);
    Bitmap bitmap = null;
    if (!isDefaultIcon) {
        bitmap = getIconBitmap(context, iconUrl);
    }
    String fontColor = dataInfo.getFontColor();
    RemoteViews remoteViews = null;
    if (!TextUtils.isEmpty(fontColor)) {
        int color = BUtility.parseColor(fontColor);
        int alphaColor = parseAlphaColor(fontColor);
        remoteViews = new RemoteViews(intent.getPackage(), EUExUtil.getResLayoutID("push_notification_view"));
        // Title
        remoteViews.setTextViewText(EUExUtil.getResIdID("notification_title"), title);
        remoteViews.setTextColor(EUExUtil.getResIdID("notification_title"), color);
        // Body
        remoteViews.setTextViewText(EUExUtil.getResIdID("notification_body"), body);
        remoteViews.setTextColor(EUExUtil.getResIdID("notification_body"), alphaColor);
        // LargeIcon
        if (bitmap != null) {
            remoteViews.setImageViewBitmap(EUExUtil.getResIdID("notification_largeIcon"), bitmap);
        } else {
            remoteViews.setImageViewResource(EUExUtil.getResIdID("notification_largeIcon"),
                    EUExUtil.getResDrawableID("icon"));
        }
        // Time
        SimpleDateFormat format = new SimpleDateFormat("HH:mm");
        remoteViews.setTextViewText(EUExUtil.getResIdID("notification_time"),
                format.format(System.currentTimeMillis()));
        remoteViews.setTextColor(EUExUtil.getResIdID("notification_time"), alphaColor);
        builder.setContent(remoteViews);
    }

    Intent notiIntent = new Intent(context, EBrowserActivity.class);
    notiIntent.putExtra("ntype", F_TYPE_PUSH);
    notiIntent.putExtra("data", body);
    notiIntent.putExtra("message", message);
    Bundle bundle = new Bundle();
    bundle.putSerializable(PushReportConstants.PUSH_DATA_INFO_KEY, dataInfo);
    notiIntent.putExtras(bundle);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, notificationNB, notiIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(pendingIntent);

    NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = builder.build();
    // Android v4bug2.3?Builder?NotificationRemoteView??
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB && remoteViews != null) {
        notification.contentView = remoteViews;
    }
    manager.notify(notificationNB, notification);
    notificationNB++;
}

From source file:com.craftsilicon.littlecabrider.GCMIntentService.java

private void generateNotificationNew(Context context, String message) {
    final Notification.Builder builder = new Notification.Builder(this);
    builder.setDefaults(/*from  w  w w .  ja va2s.  co  m*/
            Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE);
    builder.setStyle(new Notification.BigTextStyle(builder).bigText(message)
            .setBigContentTitle(context.getString(R.string.app_name)))
            .setContentTitle(context.getString(R.string.app_name)).setContentText(message)
            .setSmallIcon(R.drawable.ic_launcher);
    builder.setAutoCancel(true);
    Intent notificationIntent = new Intent(context, MainDrawerActivity.class);
    notificationIntent.putExtra("fromNotification", "notification");
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(intent);
    final NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    nm.notify(0, builder.build());
}

From source file:pj.rozkladWKD.C2DMReceiver.java

public void showNotification(String ticker, String contentTitle, String contentText, PendingIntent intent,
        int number) {
    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);

    int icon = R.drawable.ic_launcher_wkd;
    CharSequence tickerText = ticker;
    long when = System.currentTimeMillis();

    Notification notification = new Notification(icon, tickerText, when);
    Context context = getApplicationContext();
    notification.number = Prefs.getNotificationMessageNextNumber(context);

    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    SharedPreferences prefs = Prefs.get(context);
    if (prefs.getBoolean(Prefs.NOTIFICATION_SOUND, true))
        notification.defaults |= Notification.DEFAULT_SOUND;
    if (prefs.getBoolean(Prefs.NOTIFICATION_VIBRATION, true))
        notification.defaults |= Notification.DEFAULT_VIBRATE;
    notification.defaults |= Notification.DEFAULT_LIGHTS;

    notification.setLatestEventInfo(context, contentTitle, contentText, intent);

    mNotificationManager.notify(NOTIFICATION_ID, notification);

}

From source file:com.money.manager.ex.notifications.RepeatingTransactionNotifications.java

public void notifyRepeatingTransaction() {
    // create application
    CurrencyUtils currencyUtils = new CurrencyUtils(context);
    // init currencies
    if (!currencyUtils.isInit())
        currencyUtils.init();/*from w w  w . j  ava 2 s . c  o m*/

    // select data
    QueryBillDeposits billDeposits = new QueryBillDeposits(context);
    MoneyManagerOpenHelper databaseHelper = new MoneyManagerOpenHelper(context);

    if (databaseHelper != null) {
        Cursor cursor = databaseHelper.getReadableDatabase().rawQuery(billDeposits.getSource() + " AND "
                + QueryBillDeposits.DAYSLEFT + "<=0 ORDER BY " + QueryBillDeposits.NEXTOCCURRENCEDATE, null);
        if (cursor != null) {
            if (cursor.getCount() > 0) {
                cursor.moveToFirst();
                NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
                while (!cursor.isAfterLast()) {
                    String line = cursor
                            .getString(cursor.getColumnIndex(QueryBillDeposits.USERNEXTOCCURRENCEDATE)) + " "
                            + cursor.getString(cursor.getColumnIndex(QueryBillDeposits.PAYEENAME)) + ": <b>"
                            + currencyUtils.getCurrencyFormatted(
                                    cursor.getInt(cursor.getColumnIndex(QueryBillDeposits.CURRENCYID)),
                                    cursor.getDouble(cursor.getColumnIndex(QueryBillDeposits.AMOUNT)))
                            + "</b>";
                    // add line
                    inboxStyle.addLine(Html.fromHtml("<small>" + line + "</small>"));
                    // move to next row
                    cursor.moveToNext();
                }

                NotificationManager notificationManager = (NotificationManager) context
                        .getSystemService(Context.NOTIFICATION_SERVICE);
                // create pendig intent
                Intent intent = new Intent(context, RepeatingTransactionListActivity.class);
                // set launch from notification // check pin code
                intent.putExtra(RepeatingTransactionListActivity.INTENT_EXTRA_LAUNCH_NOTIFICATION, true);

                PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
                // create notification
                Notification notification = null;
                try {
                    notification = new NotificationCompat.Builder(context).setAutoCancel(true)
                            .setContentIntent(pendingIntent)
                            .setContentTitle(context.getString(R.string.application_name))
                            .setContentText(
                                    context.getString(R.string.notification_repeating_transaction_expired))
                            .setSubText(context
                                    .getString(R.string.notification_click_to_check_repeating_transaction))
                            .setSmallIcon(R.drawable.ic_stat_notification)
                            .setTicker(context.getString(R.string.notification_repeating_transaction_expired))
                            .setDefaults(Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND
                                    | Notification.DEFAULT_LIGHTS)
                            .setNumber(cursor.getCount()).setStyle(inboxStyle).build();
                    // notify 
                    notificationManager.cancel(ID_NOTIFICATION);
                    notificationManager.notify(ID_NOTIFICATION, notification);
                } catch (Exception e) {
                    Log.e(LOGCAT, e.getMessage());
                }
            }
            // close cursor
            cursor.close();
        }
        // close database helper
        //databaseHelper.close();
    }
}