remove setLatestEventInfo from API samples
Bug: 18510449 Change-Id: I26a9dbc6c92b226e28798e5a348c9357c85405ab
This commit is contained in:
@@ -99,17 +99,19 @@ public class AlarmService_Service extends Service {
|
||||
// In this sample, we'll use the same text for the ticker and the expanded notification
|
||||
CharSequence text = getText(R.string.alarm_service_started);
|
||||
|
||||
// Set the icon, scrolling text and timestamp
|
||||
Notification notification = new Notification(R.drawable.stat_sample, text,
|
||||
System.currentTimeMillis());
|
||||
|
||||
// The PendingIntent to launch our activity if the user selects this notification
|
||||
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
|
||||
new Intent(this, AlarmService.class), 0);
|
||||
|
||||
// Set the info for the views that show in the notification panel.
|
||||
notification.setLatestEventInfo(this, getText(R.string.alarm_service_label),
|
||||
text, contentIntent);
|
||||
Notification notification = new Notification.Builder(this)
|
||||
.setSmallIcon(R.drawable.stat_sample) // the status icon
|
||||
.setTicker(text) // the status text
|
||||
.setWhen(System.currentTimeMillis()) // the time stamp
|
||||
.setContentTitle(getText(R.string.alarm_service_label)) // the label of the entry
|
||||
.setContentText(text) // the contents of the entry
|
||||
.setContentIntent(contentIntent) // The intent to send when the entry is clicked
|
||||
.build();
|
||||
|
||||
// Send the notification.
|
||||
// We use a layout id because it is a unique number. We use it later to cancel.
|
||||
|
||||
@@ -166,18 +166,19 @@ public class ForegroundService extends Service {
|
||||
// In this sample, we'll use the same text for the ticker and the expanded notification
|
||||
CharSequence text = getText(R.string.foreground_service_started);
|
||||
|
||||
// Set the icon, scrolling text and timestamp
|
||||
Notification notification = new Notification(R.drawable.stat_sample, text,
|
||||
System.currentTimeMillis());
|
||||
|
||||
// The PendingIntent to launch our activity if the user selects this notification
|
||||
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
|
||||
new Intent(this, Controller.class), 0);
|
||||
|
||||
// Set the info for the views that show in the notification panel.
|
||||
notification.setLatestEventInfo(this, getText(R.string.local_service_label),
|
||||
text, contentIntent);
|
||||
|
||||
Notification notification = new Notification.Builder(this)
|
||||
.setSmallIcon(R.drawable.stat_sample) // the status icon
|
||||
.setTicker(text) // the status text
|
||||
.setWhen(System.currentTimeMillis()) // the time stamp
|
||||
.setContentTitle(getText(R.string.alarm_service_label)) // the label
|
||||
.setContentText(text) // the contents of the entry
|
||||
.setContentIntent(contentIntent) // The intent to send when clicked
|
||||
.build();
|
||||
|
||||
startForegroundCompat(R.string.foreground_service_started, notification);
|
||||
|
||||
} else if (ACTION_BACKGROUND.equals(intent.getAction())) {
|
||||
|
||||
@@ -121,24 +121,26 @@ public class IncomingMessage extends Activity {
|
||||
// The ticker text, this uses a formatted string so our message could be localized
|
||||
String tickerText = getString(R.string.imcoming_message_ticker_text, message);
|
||||
|
||||
// construct the Notification object.
|
||||
Notification notif = new Notification(R.drawable.stat_sample, tickerText,
|
||||
System.currentTimeMillis());
|
||||
|
||||
// Set the info for the views that show in the notification panel.
|
||||
notif.setLatestEventInfo(this, from, message, contentIntent);
|
||||
Notification.Builder notifBuilder = new Notification.Builder(this)
|
||||
.setSmallIcon(R.drawable.stat_sample) // the status icon
|
||||
.setTicker(tickerText) // the status text
|
||||
.setWhen(System.currentTimeMillis()) // the time stamp
|
||||
.setContentTitle(from) // the label of the entry
|
||||
.setContentText(message) // the contents of the entry
|
||||
.setContentIntent(contentIntent); // The intent to send when the entry is clicked
|
||||
|
||||
// We'll have this notification do the default sound, vibration, and led.
|
||||
// Note that if you want any of these behaviors, you should always have
|
||||
// a preference for the user to turn them off.
|
||||
notif.defaults = Notification.DEFAULT_ALL;
|
||||
notifBuilder.setDefaults(Notification.DEFAULT_ALL);
|
||||
|
||||
// Note that we use R.layout.incoming_message_panel as the ID for
|
||||
// the notification. It could be any integer you want, but we use
|
||||
// the convention of using a resource id for a string related to
|
||||
// the notification. It will always be a unique number within your
|
||||
// application.
|
||||
nm.notify(R.string.imcoming_message_ticker_text, notif);
|
||||
nm.notify(R.string.imcoming_message_ticker_text, notifBuilder.build());
|
||||
}
|
||||
//END_INCLUDE(app_notification)
|
||||
|
||||
@@ -174,24 +176,26 @@ public class IncomingMessage extends Activity {
|
||||
// The ticker text, this uses a formatted string so our message could be localized
|
||||
String tickerText = getString(R.string.imcoming_message_ticker_text, message);
|
||||
|
||||
// construct the Notification object.
|
||||
Notification notif = new Notification(R.drawable.stat_sample, tickerText,
|
||||
System.currentTimeMillis());
|
||||
|
||||
// Set the info for the views that show in the notification panel.
|
||||
notif.setLatestEventInfo(this, from, message, contentIntent);
|
||||
Notification.Builder notifBuilder = new Notification.Builder(this)
|
||||
.setSmallIcon(R.drawable.stat_sample) // the status icon
|
||||
.setTicker(tickerText) // the status text
|
||||
.setWhen(System.currentTimeMillis()) // the time stamp
|
||||
.setContentTitle(from) // the label of the entry
|
||||
.setContentText(message) // the contents of the entry
|
||||
.setContentIntent(contentIntent); // The intent to send when the entry is clicked
|
||||
|
||||
// We'll have this notification do the default sound, vibration, and led.
|
||||
// Note that if you want any of these behaviors, you should always have
|
||||
// a preference for the user to turn them off.
|
||||
notif.defaults = Notification.DEFAULT_ALL;
|
||||
notifBuilder.setDefaults(Notification.DEFAULT_ALL);
|
||||
|
||||
// Note that we use R.layout.incoming_message_panel as the ID for
|
||||
// the notification. It could be any integer you want, but we use
|
||||
// the convention of using a resource id for a string related to
|
||||
// the notification. It will always be a unique number within your
|
||||
// application.
|
||||
nm.notify(R.string.imcoming_message_ticker_text, notif);
|
||||
nm.notify(R.string.imcoming_message_ticker_text, notifBuilder.build());
|
||||
}
|
||||
//END_INCLUDE(interstitial_notification)
|
||||
}
|
||||
|
||||
@@ -100,17 +100,19 @@ public class LocalService extends Service {
|
||||
// In this sample, we'll use the same text for the ticker and the expanded notification
|
||||
CharSequence text = getText(R.string.local_service_started);
|
||||
|
||||
// Set the icon, scrolling text and timestamp
|
||||
Notification notification = new Notification(R.drawable.stat_sample, text,
|
||||
System.currentTimeMillis());
|
||||
|
||||
// The PendingIntent to launch our activity if the user selects this notification
|
||||
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
|
||||
new Intent(this, LocalServiceActivities.Controller.class), 0);
|
||||
|
||||
// Set the info for the views that show in the notification panel.
|
||||
notification.setLatestEventInfo(this, getText(R.string.local_service_label),
|
||||
text, contentIntent);
|
||||
Notification notification = new Notification.Builder(this)
|
||||
.setSmallIcon(R.drawable.stat_sample) // the status icon
|
||||
.setTicker(text) // the status text
|
||||
.setWhen(System.currentTimeMillis()) // the time stamp
|
||||
.setContentTitle(getText(R.string.local_service_label)) // the label of the entry
|
||||
.setContentText(text) // the contents of the entry
|
||||
.setContentIntent(contentIntent) // The intent to send when the entry is clicked
|
||||
.build();
|
||||
|
||||
// Send the notification.
|
||||
mNM.notify(NOTIFICATION, notification);
|
||||
|
||||
@@ -149,17 +149,19 @@ public class MessengerService extends Service {
|
||||
// In this sample, we'll use the same text for the ticker and the expanded notification
|
||||
CharSequence text = getText(R.string.remote_service_started);
|
||||
|
||||
// Set the icon, scrolling text and timestamp
|
||||
Notification notification = new Notification(R.drawable.stat_sample, text,
|
||||
System.currentTimeMillis());
|
||||
|
||||
// The PendingIntent to launch our activity if the user selects this notification
|
||||
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
|
||||
new Intent(this, Controller.class), 0);
|
||||
|
||||
// Set the info for the views that show in the notification panel.
|
||||
notification.setLatestEventInfo(this, getText(R.string.remote_service_label),
|
||||
text, contentIntent);
|
||||
Notification notification = new Notification.Builder(this)
|
||||
.setSmallIcon(R.drawable.stat_sample) // the status icon
|
||||
.setTicker(text) // the status text
|
||||
.setWhen(System.currentTimeMillis()) // the time stamp
|
||||
.setContentTitle(getText(R.string.local_service_label)) // the label of the entry
|
||||
.setContentText(text) // the contents of the entry
|
||||
.setContentIntent(contentIntent) // The intent to send when the entry is clicked
|
||||
.build();
|
||||
|
||||
// Send the notification.
|
||||
// We use a string id because it is a unique number. We use it later to cancel.
|
||||
|
||||
@@ -94,20 +94,23 @@ public class NotifyingService extends Service {
|
||||
// In this sample, we'll use the same text for the ticker and the expanded notification
|
||||
CharSequence text = getText(textId);
|
||||
|
||||
// Set the icon, scrolling text and timestamp.
|
||||
// Note that in this example, we pass null for tickerText. We update the icon enough that
|
||||
// it is distracting to show the ticker text every time it changes. We strongly suggest
|
||||
// that you do this as well. (Think of of the "New hardware found" or "Network connection
|
||||
// changed" messages that always pop up)
|
||||
Notification notification = new Notification(moodId, null, System.currentTimeMillis());
|
||||
|
||||
// The PendingIntent to launch our activity if the user selects this notification
|
||||
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
|
||||
new Intent(this, NotifyingController.class), 0);
|
||||
|
||||
// Set the icon and timestamp.
|
||||
// Note that in this example, we do not set the tickerText. We update the icon enough that
|
||||
// it is distracting to show the ticker text every time it changes. We strongly suggest
|
||||
// that you do this as well. (Think of of the "New hardware found" or "Network connection
|
||||
// changed" messages that always pop up)
|
||||
// Set the info for the views that show in the notification panel.
|
||||
notification.setLatestEventInfo(this, getText(R.string.status_bar_notifications_mood_title),
|
||||
text, contentIntent);
|
||||
Notification notification = new Notification.Builder(this)
|
||||
.setSmallIcon(moodId)
|
||||
.setWhen(System.currentTimeMillis())
|
||||
.setContentTitle(getText(R.string.status_bar_notifications_mood_title))
|
||||
.setContentText(text) // the contents of the entry
|
||||
.setContentIntent(contentIntent) // The intent to send when the entry is clicked
|
||||
.build();
|
||||
|
||||
// Send the notification.
|
||||
// We use a layout id because it is a unique number. We use it later to cancel.
|
||||
|
||||
@@ -190,17 +190,19 @@ public class RemoteService extends Service {
|
||||
// In this sample, we'll use the same text for the ticker and the expanded notification
|
||||
CharSequence text = getText(R.string.remote_service_started);
|
||||
|
||||
// Set the icon, scrolling text and timestamp
|
||||
Notification notification = new Notification(R.drawable.stat_sample, text,
|
||||
System.currentTimeMillis());
|
||||
|
||||
// The PendingIntent to launch our activity if the user selects this notification
|
||||
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
|
||||
new Intent(this, Controller.class), 0);
|
||||
|
||||
// Set the info for the views that show in the notification panel.
|
||||
notification.setLatestEventInfo(this, getText(R.string.remote_service_label),
|
||||
text, contentIntent);
|
||||
Notification notification = new Notification.Builder(this)
|
||||
.setSmallIcon(R.drawable.stat_sample) // the status icon
|
||||
.setTicker(text) // the status text
|
||||
.setWhen(System.currentTimeMillis()) // the time stamp
|
||||
.setContentTitle(getText(R.string.remote_service_label)) // the label of the entry
|
||||
.setContentText(text) // the contents of the entry
|
||||
.setContentIntent(contentIntent) // The intent to send when the entry is clicked
|
||||
.build();
|
||||
|
||||
// Send the notification.
|
||||
// We use a string id because it is a unique number. We use it later to cancel.
|
||||
|
||||
@@ -174,24 +174,25 @@ public class ServiceStartArguments extends Service {
|
||||
* Show a notification while this service is running.
|
||||
*/
|
||||
private void showNotification(String text) {
|
||||
// Set the icon, scrolling text and timestamp
|
||||
Notification notification = new Notification(R.drawable.stat_sample, text,
|
||||
System.currentTimeMillis());
|
||||
|
||||
// The PendingIntent to launch our activity if the user selects this notification
|
||||
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
|
||||
new Intent(this, Controller.class), 0);
|
||||
|
||||
// Set the info for the views that show in the notification panel.
|
||||
notification.setLatestEventInfo(this, getText(R.string.service_start_arguments_label),
|
||||
text, contentIntent);
|
||||
Notification.Builder noteBuilder = new Notification.Builder(this)
|
||||
.setSmallIcon(R.drawable.stat_sample) // the status icon
|
||||
.setTicker(text) // the status text
|
||||
.setWhen(System.currentTimeMillis()) // the time stamp
|
||||
.setContentTitle(getText(R.string.service_start_arguments_label)) // the label
|
||||
.setContentText(text) // the contents of the entry
|
||||
.setContentIntent(contentIntent); // The intent to send when the entry is clicked
|
||||
|
||||
// We show this for as long as our service is processing a command.
|
||||
notification.flags |= Notification.FLAG_ONGOING_EVENT;
|
||||
noteBuilder.setOngoing(true);
|
||||
|
||||
// Send the notification.
|
||||
// We use a string id because it is a unique number. We use it later to cancel.
|
||||
mNM.notify(R.string.service_created, notification);
|
||||
mNM.notify(R.string.service_created, noteBuilder.build());
|
||||
}
|
||||
|
||||
private void hideNotification() {
|
||||
|
||||
@@ -194,20 +194,25 @@ public class StatusBarNotifications extends Activity {
|
||||
// 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());
|
||||
// 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.setLatestEventInfo(this, getText(R.string.status_bar_notifications_mood_title),
|
||||
text, makeMoodIntent(moodId));
|
||||
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, notification);
|
||||
mNotificationManager.notify(MOOD_NOTIFICATIONS, notifBuidler.build());
|
||||
}
|
||||
|
||||
private void setMoodView(int moodId, int textId) {
|
||||
@@ -239,29 +244,27 @@ public class StatusBarNotifications extends Activity {
|
||||
}
|
||||
|
||||
private void setDefault(int defaults) {
|
||||
|
||||
// This method sets the defaults on the notification before posting it.
|
||||
|
||||
|
||||
// This is who should be launched if the user selects our notification.
|
||||
PendingIntent contentIntent = makeDefaultIntent();
|
||||
|
||||
// In this sample, we'll use the same text for the ticker and the expanded notification
|
||||
CharSequence text = getText(R.string.status_bar_notifications_happy_message);
|
||||
|
||||
final Notification notification = new Notification(
|
||||
R.drawable.stat_happy, // the icon for the status bar
|
||||
text, // the text to display in the ticker
|
||||
System.currentTimeMillis()); // the timestamp for the notification
|
||||
// In this sample, we'll use this text for the title of the notification
|
||||
CharSequence title = getText(R.string.status_bar_notifications_mood_title);
|
||||
|
||||
notification.setLatestEventInfo(
|
||||
this, // the context to use
|
||||
getText(R.string.status_bar_notifications_mood_title),
|
||||
// the title for the notification
|
||||
text, // the details to display in the notification
|
||||
contentIntent); // the contentIntent (see above)
|
||||
// Set the info for the views that show in the notification panel.
|
||||
Notification notification = new Notification.Builder(this) // the context to use
|
||||
.setSmallIcon(R.drawable.stat_happy) // the status icon
|
||||
.setTicker(text) // the text to display in the ticker
|
||||
.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(contentIntent) // The intent to send when the entry is clicked
|
||||
.setDefaults(defaults)
|
||||
.build();
|
||||
|
||||
notification.defaults = defaults;
|
||||
|
||||
mNotificationManager.notify(
|
||||
MOOD_NOTIFICATIONS, // we use a string id because it is a unique
|
||||
// number. we use it later to cancel the notification
|
||||
|
||||
Reference in New Issue
Block a user