List of usage examples for android.app Notification FLAG_SHOW_LIGHTS
int FLAG_SHOW_LIGHTS
To view the source code for android.app Notification FLAG_SHOW_LIGHTS.
Click Source Link
From source file:com.lhtechnologies.DoorApp.AuthenticatedReceiver.java
@Override public void onReceive(Context context, Intent intent) { Log.e(this.getClass().getSimpleName(), "Received Broadcast!"); if (intent.getAction().equals(AuthenticationFinishedBroadCast)) { String reason;//ww w . j a v a2s . co m mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); //Start the notification NotificationCompat.Builder notiBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_launcher).setContentTitle(context.getString(R.string.app_name)); if (intent.hasExtra(AuthenticatorReturnCode)) { String returnCode = intent.getStringExtra(AuthenticatorReturnCode); if (returnCode.equals(ServerReturnSuccess)) { if (intent.hasExtra(FlatDoor)) { notiBuilder.setContentText(context.getString(R.string.StatusBuzzing)).setOngoing(true) .setDefaults(Notification.FLAG_SHOW_LIGHTS).setLights(0xFF00FF00, 1000, 1000); mNotificationManager.notify(BuzzingNotificationId, notiBuilder.build()); class RemoveBuzzingNotification extends TimerTask { public void run() { mNotificationManager.cancel(BuzzingNotificationId); timer.cancel(); //Terminate the timer thread } } timer = new Timer(); timer.schedule(new RemoveBuzzingNotification(), buzzerTimeout * 1000); } else { notiBuilder.setContentText(context.getString(R.string.StatusAuthenticated)).setOngoing(true) .setDefaults(Notification.FLAG_SHOW_LIGHTS).setLights(0xFF00FF00, 1000, 1000); mNotificationManager.notify(SuccessNotificationId, notiBuilder.build()); class RemoveSuccessNotification extends TimerTask { public void run() { mNotificationManager.cancel(SuccessNotificationId); timer.cancel(); //Terminate the timer thread } } timer = new Timer(); timer.schedule(new RemoveSuccessNotification(), timeout * 1000); } } else { String result = intent.getStringExtra(AuthenticatorReturnCode); if (result.equals(ServerReturnAuthFailure)) reason = context.getString(R.string.AuthFailureExplanantion); else if (result.equals(ServerReturnInternalFailure)) reason = context.getString(R.string.InternalFailureExplanantion); else if (result.equals(ServerReturnRegistrationStarted)) reason = context.getString(R.string.RegistrationStartedExplanantion); else if (result.equals(ServerReturnRegistrationPending)) reason = context.getString(R.string.RegistrationPendingExplanantion); else if (result.equals(ClientErrorUndefined)) reason = context.getString(R.string.ClientErrorExplanantion) + "\n" + intent.getStringExtra(AuthenticatorErrorDescription); else if (result.equals(ClientErrorMalformedURL)) reason = context.getString(R.string.MalformedURLExplanation); else reason = context.getString(R.string.UnknownErrorExplanation); notiBuilder .setContentText(reason).setOngoing(false).setDefaults(Notification.FLAG_SHOW_LIGHTS | Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE) .setLights(0xFFFF0000, 500, 500); // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(context, MainActivity.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(MainActivity.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); notiBuilder.setContentIntent(resultPendingIntent); mNotificationManager.notify(FailureNotificationId, notiBuilder.build()); } } else { reason = context.getString(R.string.AuthFailureExplanantion) + "\n" + "NO_EXTRA"; notiBuilder .setContentText(reason).setOngoing(false).setDefaults(Notification.FLAG_SHOW_LIGHTS | Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE) .setLights(0xFFFF0000, 500, 500); // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(context, MainActivity.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(MainActivity.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); notiBuilder.setContentIntent(resultPendingIntent); mNotificationManager.notify(FailureNotificationId, notiBuilder.build()); } abortBroadcast(); } }
From source file:de.incoherent.suseconferenceclient.app.AlarmReceiver.java
@SuppressWarnings({ "deprecation" }) @Override//from w w w. j a va 2 s . c om public void onReceive(Context context, Intent intent) { Intent notificationIntent = new Intent(context, HomeActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); String title = intent.getStringExtra("title"); String room = intent.getStringExtra("room"); String time = intent.getStringExtra("timetext"); String message = time + ", " + room; NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(R.drawable.ic_launcher, null, System.currentTimeMillis()); notification.flags = Notification.FLAG_AUTO_CANCEL | Notification.FLAG_SHOW_LIGHTS; notification.ledARGB = context.getResources().getColor(R.color.dark_suse_green); notification.ledOffMS = 1000; notification.ledOnMS = 300; notification.setLatestEventInfo(context, title, message, contentIntent); manager.notify(13572, notification); }
From source file:net.bither.util.SystemUtil.java
public static void nmNotifyOfWallet(NotificationManager nm, Context context, int notifyId, Intent intent, String title, String contentText, int iconId, int rawId) { final NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setSmallIcon(iconId);/* www.ja v a 2 s . c o m*/ builder.setContentText(contentText); builder.setContentTitle(title); builder.setContentIntent(PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT)); builder.setWhen(System.currentTimeMillis()); Notification notification = null; if (ServiceUtil.isNoPrompt(System.currentTimeMillis())) { notification = builder.build(); notification.flags = Notification.FLAG_AUTO_CANCEL | Notification.FLAG_ONLY_ALERT_ONCE; notification.sound = null; } else { builder.setSound(Uri.parse("android.resource://" + context.getPackageName() + "/" + rawId)); notification = builder.build(); notification.flags = Notification.FLAG_AUTO_CANCEL | Notification.FLAG_ONLY_ALERT_ONCE; notification.flags |= Notification.FLAG_SHOW_LIGHTS; notification.ledARGB = 0xFF84E4FA; notification.ledOnMS = 3000; notification.ledOffMS = 2000; } nm.notify(notifyId, notification); }
From source file:jahirfiquitiva.iconshowcase.utilities.utils.NotificationUtils.java
public static void sendFirebaseNotification(Context context, Class mainActivity, Map<String, String> data, String title, String content) { Preferences mPrefs = new Preferences(context); if (!(mPrefs.getNotifsEnabled())) return;// w w w. j av a 2 s . c o m int ledColor = ThemeUtils.darkOrLight(context, R.color.dark_theme_accent, R.color.light_theme_accent); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_notifications).setContentTitle(title).setTicker(title) .setContentText(content).setAutoCancel(true).setOngoing(false).setColor(ledColor); Intent intent = new Intent(); int flag = 0; if (mPrefs.getLauncherIconShown()) { intent = new Intent(context, mainActivity); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); if (data != null) { if (data.size() > 0) { for (int i = 0; i < data.size(); i++) { String[] dataValue = data.toString().replace("{", "").replace("}", "").split(",")[i] .split("="); Timber.d("Key: " + dataValue[0] + " - Value: " + dataValue[1]); intent.putExtra(dataValue[0], dataValue[1]); } } } flag = PendingIntent.FLAG_ONE_SHOT; } PendingIntent pendingIntent = PendingIntent.getActivity(context, 0 /* Request code */, intent, flag); notificationBuilder.setContentIntent(pendingIntent); Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Resources resources = context.getResources(), systemResources = Resources.getSystem(); notificationBuilder.setSound(mPrefs.getNotifsSoundEnabled() ? ringtoneUri : null); notificationBuilder.setVibrate(mPrefs.getNotifsVibrationEnabled() ? new long[] { 500, 500 } : null); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = notificationBuilder.build(); if (mPrefs.getNotifsEnabled()) { notification.flags |= Notification.FLAG_SHOW_LIGHTS; notification.ledARGB = ledColor; notification.ledOnMS = resources.getInteger( systemResources.getIdentifier("config_defaultNotificationLedOn", "integer", "android")); notification.ledOffMS = resources.getInteger( systemResources.getIdentifier("config_defaultNotificationLedOff", "integer", "android")); } else { notification.ledOnMS = 0; notification.ledOffMS = 0; } notificationManager.notify(1 /* ID of notification */, notificationBuilder.build()); }
From source file:saphion.fragment.alarm.alert.AlarmAlertReceiver.java
@SuppressWarnings("deprecation") @Override// w w w.j ava2 s . co 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.example.bomber.GcmIntentService.java
private void sendNotification(String msg) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, EmergenciasCurso.class), 0);/* w w w .ja va 2 s . co m*/ NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.emergencia).setContentTitle("Notificacion") .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg) .setContentInfo("4").setTicker("Alerta emergencia en progreso!!") .setDefaults( Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND | Notification.FLAG_SHOW_LIGHTS) .setAutoCancel(true); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); }
From source file:im.neon.util.NotificationUtils.java
/** * Build an incoming call notification.//from w w w .j a v a 2s . c om * This notification starts the VectorHomeActivity which is in charge of centralizing the incoming call flow. * @param context the context. * @param roomName the room name in which the call is pending. * @param matrixId the matrix id * @param callId the call id. * @return the call notification. */ public static Notification buildIncomingCallNotification(Context context, String roomName, String matrixId, String callId) { NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setWhen(System.currentTimeMillis()); builder.setContentTitle(roomName); builder.setContentText(context.getString(R.string.incoming_call)); builder.setSmallIcon(R.drawable.incoming_call_notification_transparent); // clear the activity stack to home activity Intent intent = new Intent(context, VectorHomeActivity.class); intent.setFlags( Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra(VectorHomeActivity.EXTRA_CALL_SESSION_ID, matrixId); intent.putExtra(VectorHomeActivity.EXTRA_CALL_ID, callId); // Recreate the back stack TaskStackBuilder stackBuilder = TaskStackBuilder.create(context).addParentStack(VectorHomeActivity.class) .addNextIntent(intent); // android 4.3 issue // use a generator for the private requestCode. // When using 0, the intent is not created/launched when the user taps on the notification. // PendingIntent pendingIntent = stackBuilder.getPendingIntent((new Random()).nextInt(1000), PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(pendingIntent); Notification n = builder.build(); n.flags |= Notification.FLAG_SHOW_LIGHTS; n.defaults |= Notification.DEFAULT_LIGHTS; return n; }
From source file:net.bither.util.SystemUtil.java
public static void nmNotifyDefault(NotificationManager nm, Context context, int notifyId, Intent intent, String title, String contentText, int iconId) { final NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setSmallIcon(iconId);/* w w w. j av a2s . co m*/ builder.setContentText(contentText); builder.setContentTitle(title); builder.setContentIntent(PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT)); builder.setWhen(System.currentTimeMillis()); Notification notification = null; notification = builder.build(); notification.defaults = Notification.DEFAULT_SOUND; notification.flags = Notification.FLAG_AUTO_CANCEL | Notification.FLAG_ONLY_ALERT_ONCE; notification.flags |= Notification.FLAG_SHOW_LIGHTS; notification.ledARGB = 0xFF84E4FA; notification.ledOnMS = 3000; notification.ledOffMS = 2000; nm.notify(notifyId, notification); }
From source file:org.rti.rcd.ict.lgug.C2DMReceiver.java
@Override protected void onMessage(Context context, Intent intent) { //String accountName = intent.getExtras().getString(Config.C2DM_ACCOUNT_EXTRA); String accountName = intent.getStringExtra("account"); String message = intent.getExtras().getString(Config.C2DM_MESSAGE_EXTRA); Log.d(TAG, "Messaging request received for account " + accountName); // CoconutActivity c = CoconutActivity.getRef(); // c.displayMessage( message ); String ns = Context.NOTIFICATION_SERVICE; NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns); int icon = R.drawable.icon; CharSequence tickerText = "Olutindo"; long when = System.currentTimeMillis(); Notification notification = new Notification(icon, tickerText, when); notification.defaults |= Notification.DEFAULT_SOUND; notification.defaults |= Notification.DEFAULT_VIBRATE; notification.flags = Notification.FLAG_AUTO_CANCEL; notification.defaults |= Notification.DEFAULT_LIGHTS; notification.flags |= Notification.FLAG_SHOW_LIGHTS; notification.ledARGB = 0xff00ff00;/*from w w w. j ava 2 s .c o m*/ notification.ledOnMS = 300; notification.ledOffMS = 1000; //Context context = getApplicationContext(); Log.d(TAG, "Triggering once_off replication upon receipt of notification: " + message); Properties properties = new Properties(); try { InputStream rawResource = getResources().openRawResource(R.raw.coconut); properties.load(rawResource); System.out.println("The properties are now loaded"); System.out.println("properties: " + properties); } catch (Resources.NotFoundException e) { System.err.println("Did not find raw resource: " + e); } catch (IOException e) { System.err.println("Failed to open microlog property file"); } String localDb = "http://localhost:" + properties.getProperty("local_couch_app_port") + "/" + properties.getProperty("app_db"); Log.d(TAG, "localDb: " + localDb); // String localReplicationDbUrl = "http://localhost:" + properties.getProperty("local_couch_app_port") +"/_replicate"; // String replicationMasterUrl = "http://" + properties.getProperty("master_server") + "/coconut"; // String replicationDataFromMaster = "{\"_id\": \"once_off_from_master\",\"target\":\"" + localDb + "\",\"source\":\"" + replicationMasterUrl + "\"}"; // String replicationDataToMaster = "{\"_id\": \"once_off_to_master\",\"target\":\"" + replicationMasterUrl + "\",\"source\":\"" + localDb + "\"}"; // // try { // HTTPRequest.post(localReplicationDbUrl, replicationDataFromMaster); // } catch (JSONException e) { // Log.d(TAG, "Problem installing replication target FromMaster. replicationMasterUrl: " + replicationMasterUrl + " Error:" + e.getMessage()); // e.printStackTrace(); // } catch (ConnectException e) { // Log.d(TAG, "Unable to connect to replicationMasterUrl: " + replicationMasterUrl + " Error:" + e.getMessage()); // } // try { // HTTPRequest.post(localReplicationDbUrl, replicationDataToMaster); // } catch (JSONException e) { // Log.d(TAG, "Problem installing replication target ToMaster. replicationMasterUrl: " + replicationMasterUrl + " Error:" + e.getMessage()); // e.printStackTrace(); // } catch (ConnectException e) { // Log.d(TAG, "Unable to connect to replicationMasterUrl: " + replicationMasterUrl + " Error:" + e.getMessage()); // } CharSequence contentTitle = "New Olutindo Message"; //CharSequence contentText = "Hello World!"; Intent notificationIntent = new Intent(this, CoconutActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); notification.setLatestEventInfo(context, contentTitle, message, contentIntent); mNotificationManager.notify(HELLO_ID, notification); }
From source file:il.ac.shenkar.todos.notifications.NotificationService.java
@Override public void onHandleIntent(Intent intent) { taskListModel = TaskList.getSingletonObject(this); // Vibrate the mobile phone Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); //vibrator.vibrate(vibrationTime); vibrator.vibrate(vibrationTime);/*from w w w .j a v a2 s .c om*/ taskListModel.getDataBase().open(); String[] tokens = intent.getStringExtra("description").split(","); taskId = Integer.parseInt(tokens[0]); String title = tokens[1]; String windowTitle = null; String toSend = null; Task triggeredTask = null; boolean alarmRepeating = true; // check if alert was triggered by the location alert if (title.equals("GPS location nearby !")) { alarmType = "GPS"; alarmRepeating = false; taskId = intent.getIntExtra("Id", 0); windowTitle = "GPS location nearby !"; toSend = "Title: " + tokens[3] + "\n\nLocation: " + tokens[2]; triggeredTask = Utils.findTaskById(this, taskId); if (triggeredTask != null) { // remove the alarm new TaskAlarms(this).cancelProximityAlert(taskId, triggeredTask.getTaskTitle()); taskListModel.getDataBase().disableTaskLocationAlert(taskId); } } else // triggered by time alert { alarmType = "Time"; windowTitle = "Notification"; toSend = "Title: " + title + "\n\nDescription: " + tokens[2]; triggeredTask = Utils.findTaskById(this, taskId); if (triggeredTask != null) { String taskNotification = triggeredTask.getDate(); // checks if the alarm has an interval if (!taskNotification.contains("(")) { alarmRepeating = false; new TaskAlarms(this).cancelAlarm(taskId, triggeredTask.getTaskTitle()); taskListModel.getDataBase().disableTaskNotification(taskId); } } } // Prepare intent which is triggered if the // notification is selected Intent myIntent = new Intent(this, NotificationReceiverActivity.class); myIntent.putExtra("windowTitle", windowTitle); myIntent.putExtra("taskContent", toSend); PendingIntent pIntent = PendingIntent.getActivity(this, taskId, myIntent, PendingIntent.FLAG_UPDATE_CURRENT); // Build notification Notification noti = new Notification.Builder(this).setContentTitle(title).setContentText(tokens[2]) .setSmallIcon(R.drawable.app_icon).setContentIntent(pIntent).build(); NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); // Hide the notification after its selected noti.flags |= Notification.FLAG_AUTO_CANCEL; noti.flags |= Notification.FLAG_SHOW_LIGHTS; noti.ledARGB = 0xff00ffff; noti.ledOnMS = 300; noti.ledOffMS = 1000; if (Utils.IS_DEFAULT_SOUND) { //To play the default sound with your notification: noti.defaults |= Notification.DEFAULT_SOUND; } else { new MediaPlayerHandler(this).playAudio(Utils.LOUD_NOTIFICATION__SOUND); } notificationManager.notify(taskId, noti); if (!alarmRepeating) { // brodcast a message to main activity messageToActivity(); } }