For applications targeting API level 11 (Android 3.0) and above, developers can take advantage of the Notification.Builder class, which makes the production of notifications far simpler than with earlier versions and also provides some extra functionality such as changing the size of the associated icon.
Here we will reproduce the status bar notification from the previous recipe for the Android 3.0 Honeycomb status bar.
Start up a new Android project in Eclipse, making sure that it is built against API level 11 or greater.
In the
onCreate()
method, underneath thesetContentView()
statement add the following declarations:final int NOTIFICATION_ID = 0; NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Beneath this set up a
Notification.Builder
, as follows:Notification.Builder builder = new Notification.Builder(this); builder.setSmallIcon(R.drawable.icon); builder.setContentText("This is...