Send a notification

1 vote · 1 comment

Useful for your threads, as they can't access the display interface.

raw ·
· download
protected void sendnotification (String title, String message) { String ns = Context.NOTIFICATION_SERVICE; NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns); int icon = R.drawable.icon; CharSequence tickerText = message; long when = System.currentTimeMillis(); Notification notification = new Notification(icon, tickerText, when); Context context = getApplicationContext(); CharSequence contentTitle = title; CharSequence contentText = message; Intent notificationIntent = new Intent(this, AndroToDo.class); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); notification.flags = Notification.FLAG_AUTO_CANCEL; notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); mNotificationManager.notify(NOTIFICATION_ID, notification); }
Add a comment

1 Comment

Thanks for the wonderful tutorial... With the help of your tutorial,I implemented notification along with alertDialog box .It works fine for sending notification from within the system.But i am unable to send notification from one system to another system(one emulator to another emulator). Basically through notifiactions i want to transfer data fron one system to another system(such as GPS coordinates of the system whish i have already calculated). Is it possible???

Reply · Oct. 22, 2011, 9 a.m.