List of usage examples for android.app NotificationManager notify
public void notify(int id, Notification notification)
From source file:org.ttrssreader.utils.Utils.java
/** * Shows a notification with the given parameters * * @param content the string to display/* w ww. ja v a 2s. c om*/ * @param time how long the process took * @param error set to true if an error occured * @param context the context */ public static void showFinishedNotification(String content, int time, boolean error, Context context, Intent intent) { if (context == null) return; NotificationManager mNotMan = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); int icon = R.drawable.icon; CharSequence title = String.format((String) context.getText(R.string.Utils_DownloadFinishedTitle), time); CharSequence ticker = context.getText(R.string.Utils_DownloadFinishedTicker); CharSequence text = content; if (content == null) text = context.getText(R.string.Utils_DownloadFinishedText); if (error) { icon = R.drawable.icon; title = context.getText(R.string.Utils_DownloadErrorTitle); ticker = context.getText(R.string.Utils_DownloadErrorTicker); } Notification notification = buildNotification(context, icon, ticker, title, text, true, intent); mNotMan.notify(ID_FINISHED, notification); }
From source file:com.commonsware.android.biglocal.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); NotificationManager mgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); NotificationCompat.Builder normal = buildNormal(); NotificationCompat.InboxStyle big = new NotificationCompat.InboxStyle(normal); mgr.notify(NOTIFY_ID, big.setSummaryText(getString(R.string.summary)).addLine(getString(R.string.entry)) .addLine(getString(R.string.another_entry)).addLine(getString(R.string.third_entry)) .addLine(getString(R.string.yet_another_entry)).addLine(getString(R.string.low)).build()); finish();// w ww .j av a 2 s.c o m }
From source file:com.android.settings.sim.SimBootReceiver.java
private void createNotification(Context context) { final Resources resources = context.getResources(); NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_sim_card_alert_white_48dp) .setColor(resources.getColor(R.color.sim_noitification)) .setContentTitle(resources.getString(R.string.sim_notification_title)) .setContentText(resources.getString(R.string.sim_notification_summary)); Intent resultIntent = new Intent(context, SimSettingsActivity.class); resultIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, PendingIntent.FLAG_CANCEL_CURRENT); builder.setContentIntent(resultPendingIntent); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(NOTIFICATION_ID, builder.build()); }
From source file:com.google.android.apps.chrometophone.C2DMReceiver.java
private void generateNotification(Context context, String msg, String title, Intent intent) { int icon = R.drawable.status_icon; long when = System.currentTimeMillis(); Notification notification = new Notification(icon, title, when); notification.setLatestEventInfo(context, title, msg, PendingIntent.getActivity(context, 0, intent, 0)); notification.defaults = Notification.DEFAULT_SOUND; notification.flags |= Notification.FLAG_AUTO_CANCEL; SharedPreferences settings = Prefs.get(context); int notificatonID = settings.getInt("notificationID", 0); // allow multiple notifications NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(notificatonID, notification); SharedPreferences.Editor editor = settings.edit(); editor.putInt("notificationID", ++notificatonID % 32); editor.commit();//from ww w . ja v a 2s . c o m }
From source file:com.capstone.transit.trans_it.Settings.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_settings); setUpButton();/*www . j a v a 2 s .c o m*/ NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.logocapstone).setContentTitle("Notification Test") .setContentText("Open app by tapping notification"); Intent resultIntent = new Intent(this, MainMenu.class); // Because clicking the notification opens a new ("special") activity, there's // no need to create an artificial back stack. PendingIntent resultPendingIntent = PendingIntent.getActivity(this, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); // Sets an ID for the notification int mNotificationId = 001; // Gets an instance of the NotificationManager service NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); // Builds the notification and issues it. mNotifyMgr.notify(mNotificationId, mBuilder.build()); }
From source file:ch.epfl.sweng.evento.gui.MainActivity.java
public void makeNotifications(List<Event> eventArrayList) { if (eventArrayList != null) { Calendar currentDate = Calendar.getInstance(); boolean notif_needed = false; String notif_description = ""; for (Event event : eventArrayList) { double diffTime = (event.getStartDate().getTimeInMillis() - currentDate.getTimeInMillis()) / (1000 * 3600 * 24); if (diffTime < 1.0) { notif_needed = true;//w w w . j av a 2 s.c o m notif_description += "The event " + event.getTitle() + " is starting tomorrow. \n"; //Toast.makeText(getApplicationContext(), "Notified event : " + event.getTitle(), Toast.LENGTH_SHORT).show(); } } if (notif_needed) { notif_description += "Don't forget to attend !"; Notification n = new Notification.Builder(this).setContentTitle("You've got events soon !") .setContentText(notif_description).setSmallIcon(R.drawable.notification).setAutoCancel(true) .build(); NotificationManager notificationManager = (NotificationManager) getSystemService( NOTIFICATION_SERVICE); notificationManager.notify(NOTIFICATION_ID, n); } } }
From source file:alaindc.crowdroid.GeofenceTransitionsIntentService.java
/** * Posts a notification in the notification bar when a transition is detected. * If the user clicks the notification, control goes to the MainActivity. *///from w w w. j a v a 2 s . com private void sendNotification(String nameofsensor) { // Create an explicit content Intent that starts the main Activity. Intent notificationIntent = new Intent(getApplicationContext(), MainActivity.class); // Construct a task stack. TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); // Add the main Activity to the task stack as the parent. stackBuilder.addParentStack(MainActivity.class); // Push the content Intent onto the stack. stackBuilder.addNextIntent(notificationIntent); // Get a PendingIntent containing the entire back stack. PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); // Get a notification builder that's compatible with platform versions >= 4 NotificationCompat.Builder builder = new NotificationCompat.Builder(this); // Define the notification settings. builder.setSmallIcon(R.drawable.icon) // In a real app, you may want to use a library like Volley // to decode the Bitmap. .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.icon)).setColor(Color.RED) .setContentTitle("Geofence Crowdroid").setContentText("Geofence Trigger: " + nameofsensor) .setContentIntent(notificationPendingIntent); // Dismiss notification once the user touches it. builder.setAutoCancel(true); // Get an instance of the Notification manager NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); // Issue the notification mNotificationManager.notify(0, builder.build()); }
From source file:com.achep.acdisplay.App.java
@Override public void onCreate() { mAccessManager = new AccessManager(this); AppHeap.getInstance().init(this); Config.getInstance().init(this); Blacklist.getInstance().init(this); SmileyParser.init(this); // Init the main notification listener. NotificationPresenter.getInstance()//from w w w .jav a 2 s . c o m .setOnNotificationPostedListener(Config.getInstance().isEnabled() ? Presenter.getInstance() : null); super.onCreate(); // Check the main switch. String divider = getString(R.string.settings_multi_list_divider); Config config = Config.getInstance(); if (config.isEnabled()) { StringBuilder sb = new StringBuilder(); boolean foundAny = false; PermissionGroup pg = getAccessManager().getMasterPermissions(); for (Permission permission : pg.permissions) { if (!permission.isActive()) { if (foundAny) { sb.append(divider); } else foundAny = true; sb.append(getString(permission.getTitleResource())); } } if (foundAny) { String list = sb.toString(); list = list.charAt(0) + list.substring(1).toLowerCase(); ConfigBase.Option option = config.getOption(Config.KEY_ENABLED); option.write(config, this, false, null); final int id = App.ID_NOTIFY_APP_AUTO_DISABLED; PendingIntent pendingIntent = PendingIntent.getActivity(this, id, new Intent(this, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT); Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher); NotificationCompat.BigTextStyle bts = new NotificationCompat.BigTextStyle() .bigText(getString(R.string.permissions_auto_disabled)).setSummaryText(list); NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setContentTitle(getString(R.string.app_name)) .setContentText(getString(R.string.permissions_auto_disabled)) .setContentIntent(pendingIntent).setLargeIcon(largeIcon) .setSmallIcon(R.drawable.stat_acdisplay).setAutoCancel(true).setStyle(bts) .setPriority(Notification.PRIORITY_HIGH).setColor(App.ACCENT_COLOR); NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(id, builder.build()); } } // Check the keyguard (without the notification). if (config.isKeyguardEnabled() && !getAccessManager().getKeyguardPermissions().isActive()) { ConfigBase.Option option = config.getOption(Config.KEY_KEYGUARD); option.write(config, this, false, null); } // Launch keyguard and (or) active mode on // app launch. KeyguardService.handleState(this); ActiveModeService.handleState(this); SensorsDumpService.handleState(this); }
From source file:com.bullmobi.message.App.java
@Override public void onCreate() { mAccessManager = new AccessManager(this); AppHeap.getInstance().init(this); Config.getInstance().init(this); Blacklist.getInstance().init(this); SmileyParser.init(this); // Init the main notification listener. NotificationPresenter.getInstance()/*from w ww. j a v a 2 s . co m*/ .setOnNotificationPostedListener(Config.getInstance().isEnabled() ? Presenter.getInstance() : null); super.onCreate(); // Check the main switch. String divider = getString(R.string.settings_multi_list_divider); Config config = Config.getInstance(); if (config.isEnabled()) { StringBuilder sb = new StringBuilder(); boolean foundAny = false; PermissionGroup pg = getAccessManager().getMasterPermissions(); for (Permission permission : pg.permissions) { if (!permission.isActive()) { if (foundAny) { sb.append(divider); } else foundAny = true; sb.append(getString(permission.getTitleResource())); } } if (foundAny) { String list = sb.toString(); list = list.charAt(0) + list.substring(1).toLowerCase(); ConfigBase.Option option = config.getOption(Config.KEY_ENABLED); option.write(config, this, false, null); final int id = App.ID_NOTIFY_APP_AUTO_DISABLED; PendingIntent pendingIntent = PendingIntent.getActivity(this, id, new Intent(this, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT); Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher); NotificationCompat.BigTextStyle bts = new NotificationCompat.BigTextStyle() .bigText(getString(R.string.permissions_auto_disabled)).setSummaryText(list); NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setContentTitle(getString(R.string.app_name)) .setContentText(getString(R.string.permissions_auto_disabled)) .setContentIntent(pendingIntent).setLargeIcon(largeIcon) .setSmallIcon(R.drawable.stat_easynotification).setAutoCancel(true).setStyle(bts) .setPriority(Notification.PRIORITY_HIGH).setColor(App.ACCENT_COLOR); NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(id, builder.build()); } } // Check the keyguard (without the notification). if (config.isKeyguardEnabled() && !getAccessManager().getKeyguardPermissions().isActive()) { ConfigBase.Option option = config.getOption(Config.KEY_KEYGUARD); option.write(config, this, false, null); } // Launch keyguard and (or) active mode on // app launch. KeyguardService.handleState(this); ActiveModeService.handleState(this); SensorsDumpService.handleState(this); }
From source file:com.example.AllSOSservice.GcmBroadcastReceiver.java
@Override public void onReceive(Context context, Intent intent) { // Explicitly specify that GcmIntentService will handle the intent. ComponentName comp = new ComponentName(context.getPackageName(), Activity.class.getName()); // Start the service, keeping the device awake while it is launching. startWakefulService(context, (intent.setComponent(comp))); setResultCode(Activity.RESULT_OK);// w ww .j av a 2 s . c o m String message = intent.getStringExtra("message"); String email = intent.getStringExtra("email"); String latitude = intent.getStringExtra("latitude"); String longitude = intent.getStringExtra("longitude"); Toast toast = Toast.makeText(context, message, Toast.LENGTH_LONG); toast.show(); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_launcher).setContentTitle("Novo Pedido de Ajuda!") .setContentText("Alguem precisa de um " + message); Intent resultIntent = null; try { if (isLoggedIn()) { resultIntent = new Intent(context, LoggedInActivity.class); } else { resultIntent = new Intent(context, LoginActivity.class); } } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); } catch (TimeoutException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } // Because clicking the notification opens a new ("special") activity, there's // no need to create an artificial back stack. PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); int mNotificationId = 001; // Gets an instance of the NotificationManager service NotificationManager mNotifyMgr = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); // Builds the notification and issues it. mNotifyMgr.notify(mNotificationId, mBuilder.build()); }