List of usage examples for android.app Notification DEFAULT_LIGHTS
int DEFAULT_LIGHTS
To view the source code for android.app Notification DEFAULT_LIGHTS.
Click Source Link
From source file:org.androidpn.client.SerivceManager.Notifier.java
public void notify(String notificationId, String apiKey, String title, String message, String uri) { Log.d(LOGTAG, "notify()..."); Log.d(LOGTAG, "notificationId=" + notificationId); Log.d(LOGTAG, "notificationApiKey=" + apiKey); Log.d(LOGTAG, "notificationTitle=" + title); Log.d(LOGTAG, "notificationMessage=" + message); Log.d(LOGTAG, "notificationUri=" + uri); if (isNotificationEnabled()) { // Show the toast if (isNotificationToastEnabled()) { Toast.makeText(context, message, Toast.LENGTH_LONG).show(); }/*from w w w . j a v a 2 s.c o m*/ // PNNotification int ntfyDefaults = Notification.DEFAULT_LIGHTS; if (isNotificationSoundEnabled()) { ntfyDefaults |= Notification.DEFAULT_SOUND; } if (isNotificationVibrateEnabled()) { ntfyDefaults |= Notification.DEFAULT_VIBRATE; } Intent intent; //launch mainactivity if (uri == null || uri.length() <= 0) { intent = new Intent(context, MainActivity.class); } else { intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(uri)); } /* intent.putExtra(Constants.NOTIFICATION_ID, notificationId); intent.putExtra(Constants.NOTIFICATION_API_KEY, apiKey); intent.putExtra(Constants.NOTIFICATION_TITLE, title); intent.putExtra(Constants.NOTIFICATION_MESSAGE, message); intent.putExtra(Constants.NOTIFICATION_URI, uri);*/ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); Notification.Builder notification = new Notification.Builder(context).setContentTitle(title) .setContentText(message).setSmallIcon(getNotificationIcon()).setDefaults(ntfyDefaults) .setContentIntent(contentIntent) //.setLargeIcon(R.drawable.notification) .setWhen(System.currentTimeMillis()).setTicker(message); notify(notification); //notification.flags |= PNNotification.FLAG_AUTO_CANCEL; // Intent intent; // if (uri != null // && uri.length() > 0 // && (uri.startsWith("http:") || uri.startsWith("https:") // || uri.startsWith("tel:") || uri.startsWith("geo:"))) { // intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri)); // } else { // String callbackActivityPackageName = sharedPrefs.getString( // Constants.CALLBACK_ACTIVITY_PACKAGE_NAME, ""); // String callbackActivityClassName = sharedPrefs.getString( // Constants.CALLBACK_ACTIVITY_CLASS_NAME, ""); // intent = new Intent().setClassName(callbackActivityPackageName, // callbackActivityClassName); // intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); // } //notification.setLatestEventInfo(context, title, message, // contentIntent); //notificationManager.notify(random.nextInt(), notification); // Intent clickIntent = new Intent( // Constants.ACTION_NOTIFICATION_CLICKED); // clickIntent.putExtra(Constants.NOTIFICATION_ID, notificationId); // clickIntent.putExtra(Constants.NOTIFICATION_API_KEY, apiKey); // clickIntent.putExtra(Constants.NOTIFICATION_TITLE, title); // clickIntent.putExtra(Constants.NOTIFICATION_MESSAGE, message); // clickIntent.putExtra(Constants.NOTIFICATION_URI, uri); // // positiveIntent.setData(Uri.parse((new StringBuilder( // // "notif://notification.adroidpn.org/")).append(apiKey).append( // // "/").append(System.currentTimeMillis()).toString())); // PendingIntent clickPendingIntent = PendingIntent.getBroadcast( // context, 0, clickIntent, 0); // // notification.setLatestEventInfo(context, title, message, // clickPendingIntent); // // Intent clearIntent = new Intent( // Constants.ACTION_NOTIFICATION_CLEARED); // clearIntent.putExtra(Constants.NOTIFICATION_ID, notificationId); // clearIntent.putExtra(Constants.NOTIFICATION_API_KEY, apiKey); // // negativeIntent.setData(Uri.parse((new StringBuilder( // // "notif://notification.adroidpn.org/")).append(apiKey).append( // // "/").append(System.currentTimeMillis()).toString())); // PendingIntent clearPendingIntent = PendingIntent.getBroadcast( // context, 0, clearIntent, 0); // notification.deleteIntent = clearPendingIntent; // // notificationManager.notify(random.nextInt(), notification); } else { Log.w(LOGTAG, "Notificaitons disabled."); } datasource = new PNNotificationDataSource(context); datasource.open(); datasource.createNotification(title, message, uri); datasource.close(); //Update the list view if (MainActivity.instance != null) { MainActivity.instance.resetList(); } }
From source file:com.nkc.education.service.NotificationHelper.java
/** * Basic Text Notification for Task Butler, using NotificationCompat * * @param context/* www . j ava2s . com*/ */ public void sendBasicNotification(Context context, Task task) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); boolean vibrate = prefs.getBoolean(AppConfig.VIBRATE_ON_ALARM, true); int alarmInterval; int alarmUnits; if (task.hasFinalDateDue()) { alarmInterval = Integer.parseInt(prefs.getString(AppConfig.ALARM_TIME, AppConfig.DEFAULT_ALARM_TIME)); alarmUnits = Calendar.MINUTE; } else { alarmInterval = Integer .parseInt(prefs.getString(AppConfig.REMINDER_TIME, AppConfig.DEFAULT_REMINDER_TIME)); alarmUnits = Calendar.HOUR_OF_DAY; } Calendar next_reminder = GregorianCalendar.getInstance(); next_reminder.add(alarmUnits, alarmInterval); Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher); NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setAutoCancel(true) .setContentIntent(getPendingIntent(context, task.getID())) .setContentInfo(Task.PRIORITY_LABELS[task.getPriority()]).setContentTitle(task.getName()) .setContentText(task.getDetail()) .setDefaults(vibrate ? Notification.DEFAULT_ALL : Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS) .setSmallIcon(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB ? R.drawable.ic_exam_name : R.drawable.ic_exam_name) .setLargeIcon(bitmap).setTicker(task.getName()).setPriority(Notification.PRIORITY_MAX) .setColor(Color.argb(255, 21, 149, 196)).setWhen(System.currentTimeMillis()); @SuppressWarnings("deprecation") Notification notification = builder.getNotification(); NotificationManager notificationManager = getNotificationManager(context); notificationManager.notify(task.getID(), notification); }
From source file:edu.worcester.cs499summer2012.service.NotificationHelper.java
/** * Basic Text Notification for Task Butler, using NotificationCompat * @param context /*www. j a v a 2s . co m*/ * @param id id of task, call task.getID() and pass it to this parameter */ public void sendBasicNotification(Context context, Task task) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); boolean vibrate = prefs.getBoolean(SettingsActivity.VIBRATE_ON_ALARM, true); int alarmInterval; int alarmUnits; if (task.hasFinalDateDue()) { alarmInterval = Integer .parseInt(prefs.getString(SettingsActivity.ALARM_TIME, SettingsActivity.DEFAULT_ALARM_TIME)); alarmUnits = Calendar.MINUTE; } else { alarmInterval = Integer.parseInt( prefs.getString(SettingsActivity.REMINDER_TIME, SettingsActivity.DEFAULT_REMINDER_TIME)); alarmUnits = Calendar.HOUR_OF_DAY; } Calendar next_reminder = GregorianCalendar.getInstance(); next_reminder.add(alarmUnits, alarmInterval); NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setAutoCancel(true) .setContentIntent(getPendingIntent(context, task.getID())) .setContentInfo(Task.PRIORITY_LABELS[task.getPriority()]).setContentTitle(task.getName()) .setContentText(DateFormat.format("'Next reminder at' h:mmaa", next_reminder)) .setDefaults(vibrate ? Notification.DEFAULT_ALL : Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS) .setSmallIcon(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB ? R.drawable.ic_notification : R.drawable.ic_notification_deprecated) .setTicker(task.getName()).setWhen(System.currentTimeMillis()); @SuppressWarnings("deprecation") Notification notification = builder.getNotification(); NotificationManager notificationManager = getNotificationManager(context); notificationManager.notify(task.getID(), notification); }
From source file:net.zionsoft.obadiah.model.notification.PushNotificationHandler.java
@NonNull private static NotificationCompat.Builder buildBasicNotificationBuilder(Context context, String messageType) { final NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setAutoCancel(true) .setDefaults(Notification.DEFAULT_LIGHTS).setVisibility(NotificationCompat.VISIBILITY_PRIVATE) .setDeleteIntent(PendingIntent.getBroadcast(context, 0, PushDismissedReceiver.newStartIntent(context, messageType), PendingIntent.FLAG_UPDATE_CURRENT)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { builder.setSmallIcon(R.drawable.ic_notification) .setColor(context.getResources().getColor(R.color.blue)); } else {/* ww w. j a v a 2s .c o m*/ builder.setSmallIcon(R.drawable.ic_launcher); } return builder; }
From source file:com.amlcurran.messages.notifications.NotificationBuilder.java
NotificationCompat.Builder getDefaultBuilder(boolean shouldSoundAndVibrate) { NotificationCompat.Builder builder = new NotificationCompat.Builder(this.context) .setContentIntent(notificationIntentFactory.createLaunchActivityIntent()).setAutoCancel(true) .setSmallIcon(R.drawable.ic_notify_sms).setCategory(NotificationCompat.CATEGORY_MESSAGE) .setColor(notificationColor).setDefaults(Notification.DEFAULT_LIGHTS); if (shouldSoundAndVibrate) { if (preferenceStore.hasRingtoneUri()) { builder.setSound(Uri.parse(preferenceStore.getRingtoneUri().toString())); } else {//ww w . j ava 2s .c o m builder.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS); } builder.setVibrate(VIBRATE_PATTERN); } return builder; }
From source file:com.farsunset.ichat.example.receiver.CIMPushManagerReceiver.java
private void showNotify(Context context, Message msg) { this.notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); String title = "?"; PendingIntent contentIntent = PendingIntent.getActivity(context, 1, new Intent(context, SystemMessageActivity.class), PendingIntent.FLAG_UPDATE_CURRENT); final NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setAutoCancel(true);/*from w w w. j ava 2 s .c o m*/ builder.setDefaults(Notification.DEFAULT_ALL); builder.setWhen(msg.getTimestamp()); builder.setSmallIcon(R.drawable.icon); builder.setTicker(title); builder.setContentTitle(title); builder.setContentText(msg.getContent()); builder.setDefaults(Notification.DEFAULT_LIGHTS); builder.setContentIntent(contentIntent); final Notification notification = builder.build(); notificationManager.notify(R.drawable.icon, notification); }
From source file:org.connectbot.service.ConnectionNotifier.java
protected Notification newActivityNotification(Context context, HostBean host) { NotificationCompat.Builder builder = newNotificationBuilder(context); Resources res = context.getResources(); String contentText = res.getString(R.string.notification_text, host.getNickname()); Intent notificationIntent = new Intent(context, ConsoleActivity.class); notificationIntent.setAction("android.intent.action.VIEW"); notificationIntent.setData(host.getUri()); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); builder.setContentTitle(res.getString(R.string.app_name)).setContentText(contentText) .setContentIntent(contentIntent); builder.setAutoCancel(true);// w ww . j av a2 s. c o m int ledOnMS = 300; int ledOffMS = 1000; builder.setDefaults(Notification.DEFAULT_LIGHTS); if (HostDatabase.COLOR_RED.equals(host.getColor())) builder.setLights(Color.RED, ledOnMS, ledOffMS); else if (HostDatabase.COLOR_GREEN.equals(host.getColor())) builder.setLights(Color.GREEN, ledOnMS, ledOffMS); else if (HostDatabase.COLOR_BLUE.equals(host.getColor())) builder.setLights(Color.BLUE, ledOnMS, ledOffMS); else builder.setLights(Color.WHITE, ledOnMS, ledOffMS); return builder.build(); }
From source file:grk.impala.GCMIntentService.java
private static void generateNotification(Context context, String message) { Intent notificationIntent = null;//from w w w . jav a2 s . c o m if (PrefUtil.getLoggedIn(context)) { if (PrefUtil.getUserType(context) == 2) { notificationIntent = new Intent(context, StatusActivity.class); } else { notificationIntent = new Intent(context, NotificationActivity.class); } } else { notificationIntent = new Intent(context, SplashActivity.class); } PendingIntent contentIntent = TaskStackBuilder.create(context) .addNextIntentWithParentStack(notificationIntent) .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.mipmap.ic_launcher).setContentTitle(context.getString(R.string.app_name)) .setStyle(new NotificationCompat.BigTextStyle().bigText(message)).setContentText(message) .setAutoCancel(true).setDefaults( Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_LIGHTS); mBuilder.setContentIntent(contentIntent); NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.cancelAll(); mNotificationManager.notify(0, mBuilder.build()); }
From source file:saphion.fragment.alarm.alert.AlarmAlertReceiver.java
@SuppressWarnings("deprecation") @Override//from w w w. j a v a 2 s . c o m public void onReceive(final Context context, final Intent intent) { String action = intent.getAction(); int pos = intent.getIntExtra(PreferenceHelper.BAT_VALS, 0); level = intent.getIntExtra(PreferenceHelper.CURR_RING, 72); //Log.Toast(context, level + " in receiver", Toast.LENGTH_LONG); // int id = intent.getIntExtra(Intents.EXTRA_ID, -1); if (action.equals(Intents.ALARM_ALERT_ACTION)) { /* Close dialogs and window shade */ Intent closeDialogs = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); context.sendBroadcast(closeDialogs); // Decide which activity to start based on the state of the // keyguard. /* * KeyguardManager km = (KeyguardManager) * context.getSystemService(Context.KEYGUARD_SERVICE); if * (km.inKeyguardRestrictedInputMode()) { // Use the full screen * activity for security. c = AlarmAlertFullScreen.class; } */ // 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. if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { Intent notify = new Intent(context, saphion.fragments.alarm.AlarmAlert.class); notify.putExtra(PreferenceHelper.BAT_VALS, pos); PendingIntent pendingNotify = PendingIntent.getActivity(context, ID, notify, 0); // Alarm alarm = AlarmsManager.getAlarmsManager().getAlarm(id); Notification n = new Notification(R.drawable.stat_notify_alarm, "abc", System.currentTimeMillis()); n.setLatestEventInfo(context, "Battery Alarm", "Battery Level is " + level, pendingNotify); n.flags |= Notification.FLAG_SHOW_LIGHTS | Notification.FLAG_ONGOING_EVENT; n.defaults |= Notification.DEFAULT_LIGHTS; // NEW: Embed the full-screen UI here. The notification manager // will // take care of displaying it if it's OK to do so. Intent alarmAlert = new Intent(context, saphion.fragments.alarm.AlarmAlert.class); alarmAlert.putExtra(PreferenceHelper.CURR_RING, level); alarmAlert.putExtra(PreferenceHelper.BAT_VALS, pos); alarmAlert.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_USER_ACTION); n.fullScreenIntent = PendingIntent.getActivity(context, ID, alarmAlert, 0); // Send the notification using the alarm id to easily identify // the // correct notification. NotificationManager nm = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); // Log.Toast(context, "Recieved", Toast.LENGTH_LONG); // mNotificationManager.notify(ID, builder.build()); nm.notify(ID, n); } else { // Log.Toast(context, "Recieved", Toast.LENGTH_LONG); newMethod(context, pos); } } else if (action.equals(Intents.ALARM_DISMISS_ACTION)) { NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); nm.cancel(ID); } }
From source file:com.andrada.sitracker.tasks.receivers.UpdateStatusNotificationReceiver.java
private void sendNotification(int number, List<String> updatedAuthorNames, @NotNull Context context) { NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); int maxLines = 4; if (updatedAuthorNames.size() < maxLines) { maxLines = updatedAuthorNames.size(); }//ww w. j av a 2 s .c o m for (int i = 0; i < maxLines; i++) { inboxStyle.addLine(updatedAuthorNames.get(i)); } if (updatedAuthorNames.size() > 4) { inboxStyle.setSummaryText( context.getString(R.string.notification_more_summary, updatedAuthorNames.size() - 4)); } NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.notification) .setContentTitle(context.getResources().getString(R.string.notification_title)) .setContentText(context.getResources().getQuantityString(R.plurals.authors_updated, number, number)) .setAutoCancel(true).setOnlyAlertOnce(true) .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND).setNumber(number) .setStyle(inboxStyle); // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(context, HomeActivity_.class); // The stack builder object will contain an artificial back stack for the // started Activity. // This ensures that navigating backward from the Activity leads out of // your application to the Home screen. TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(HomeActivity_.class); // Adds the Intent that starts the Activity to the top of the stack stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(UPDATE_SUCCESS_NOTIFICATION_ID, mBuilder.build()); }