The following android application will create a “Hello World” notification in the status bar. Just copy the following code and paste it in your android app:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //Create notification service reference String ns = Context.NOTIFICATION_SERVICE; NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns); //Notification icon int icon = R.drawable.icon; CharSequence tickerText = "Hello"; //When to show notification long when = System.currentTimeMillis(); Notification notification = new Notification(icon, tickerText, when); Context context = getApplicationContext(); //Notification title and text CharSequence notificationTitle = "My notification"; CharSequence notificationText = "Hello World!"; //Notification intent Intent notificationIntent = new Intent(this, NotificationAppActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); notification.setLatestEventInfo(context, notificationTitle, notificationText, contentIntent); final int HELLO_ID = 1; //Show notification mNotificationManager.notify(HELLO_ID, notification); } |
Incoming search terms:
- Simple status bar android



