private void setMood(int moodId, int textId, boolean showTicker) { // In this sample, we'll use the same text for the ticker and the expanded notification CharSequence text = getText(textId); // choose the ticker text String tickerText = showTicker ? getString(textId) : null; // Set the icon, scrolling text and timestamp Notification notification = new Notification(moodId, tickerText, System.currentTimeMillis()); // Set the info for the views that show in the notification panel. notification.setLatestEventInfo(this, getText(R.string.status_bar_notifications_mood_title), text, makeMoodIntent(moodId)); // Send the notification. // We use a layout id because it is a unique number. We use it later to cancel. mNotificationManager.notify(MOOD_NOTIFICATIONS, notification); }
private void setMoodView(int moodId, int textId) { // Instead of the normal constructor, we're going to use the one with no args and fill // in all of the data ourselves. The normal one uses the default layout for notifications. // You probably want that in most cases, but if you want to do something custom, you // can set the contentView field to your own RemoteViews object. Notification notif = new Notification(); // This is who should be launched if the user selects our notification. notif.contentIntent = makeMoodIntent(moodId); // In this sample, we'll use the same text for the ticker and the expanded notification CharSequence text = getText(textId); notif.tickerText = text; // the icon for the status bar notif.icon = moodId; // our custom view RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.status_bar_balloon); contentView.setTextViewText(R.id.text, text); contentView.setImageViewResource(R.id.icon, moodId); notif.contentView = contentView; // we use a string id because is a unique number. we use it later to cancel the // notification mNotificationManager.notify(MOOD_NOTIFICATIONS, notif); }
private void setMoodView(int moodId, int textId) { // Instead of the normal constructor, we're going to use the one with no args and fill // in all of the data ourselves. The normal one uses the default layout for notifications. // You probably want that in most cases, but if you want to do something custom, you // can set the contentView field to your own RemoteViews object. Notification notif = new Notification(); // This is who should be launched if the user selects our notification. notif.contentIntent = makeMoodIntent(moodId); // In this sample, we'll use the same text for the ticker and the expanded notification CharSequence text = getText(textId); notif.tickerText = text; // the icon for the status bar notif.icon = moodId; // our custom view RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.status_bar_balloon); contentView.setTextViewText(R.id.text, text); contentView.setImageViewResource(R.id.icon, moodId); notif.contentView = contentView; // we use a string id because is a unique number. we use it later to cancel the // notification mNotificationManager.notify(MOOD_NOTIFICATIONS, notif); }
private void setMood(int moodId, int textId, boolean showTicker) { // In this sample, we'll use the same text for the ticker and the expanded notification CharSequence text = getText(textId); // In this sample, we'll use this text for the title of the notification CharSequence title = getText(R.string.status_bar_notifications_mood_title); // Set the info for the views that show in the notification panel. Notification.Builder notifBuidler = new Notification.Builder(this) // the context to use .setSmallIcon(moodId) // the status icon .setWhen(System.currentTimeMillis()) // the timestamp for the notification .setContentTitle(title) // the title for the notification .setContentText(text) // the details to display in the notification .setContentIntent(makeMoodIntent(moodId)); // The intent to send clicked if (showTicker) { // include the ticker text notifBuidler.setTicker(getString(textId)); } // Send the notification. // We use a layout id because it is a unique number. We use it later to cancel. mNotificationManager.notify(MOOD_NOTIFICATIONS, notifBuidler.build()); }