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); }