I am trying to get a simple notification. I've seen lots of examples using old API methods, but i want to use the newer method. I have put this code together from the API resource, and it runs without error. However, i am not seeing any notifications. I have the minimum required to view a notification, at least, i believe so from what i have read. Here is my code :
public class Login extends Activity { public static Context ctx; public void onCreate(Bundle savedInstanceState) { ctx = this; } private static void notice(String msgfrom, String msg) { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(ctx); mBuilder.setSmallIcon(R.drawable.ic_launcher); mBuilder.setContentTitle("New message from " + msgfrom.toString()); mBuilder.setContentText(msg); mBuilder.build(); } } THANKS TO HELP BELOW, I MODIFIED MY CODE TO THIS
NotificationCompat.Builder nb = new NotificationCompat.Builder(ctx); nb.setSmallIcon(R.drawable.ic_launcher); nb.setContentTitle("New message from " + msgfrom.toString()); nb.setContentText(msg); nb.setAutoCancel(true); Notification notification = nb.build(); NotificationManager NM = (NotificationManager) ctx.getSystemService(NOTIFICATION_SERVICE); NM.notify(0, notification); 