android - Why does Eclipse not recognize the build() method from the Notification.Builder class to return a Notification object? -
this code:
notificationmanager mnotificationmanager = (notificationmanager) c.getsystemservice(ns); //instantiate notification charsequence tickertext = "hello"; long when = system.currenttimemillis(); notification.builder builder = new notification.builder(c) .setticker(tickertext) .setwhen(when) .setcontenttitle("test notification") .setcontenttext(arg1.getstringextra("info")) .setsmallicon(r.drawable.ic_launcher) .setautocancel(true); notification notification = builder.getnotification(); mnotificationmanager.notify(88, notification);
it works find, using notification notification = builder.getnotification();
deprecated. should doing notification notification = builder.build();
. problem eclipse isn't recognizing such, meaning won't let me compile. doc clear build()
exists , preferred method, not working on end. use non-deprecated code, appreciated.
imports
import android.app.notification; import android.app.notification.builder; import android.app.notificationmanager; import android.content.broadcastreceiver; import android.content.context; import android.content.intent; import android.util.log;
be aware import android.app.notification.builder;
saying not being used.
if want develop version sdk lower 11, can use code instead android.app.notification.builder class creation notification:
private void createnotification(){ notificationmanager mnotificationmanager = (notificationmanager) getsystemservice(context.notification_service); notification notification = new notification(r.drawable.ic_launcher, "hello", system.currenttimemillis()); intent notificationintent = new intent(this, youractivity.class); random r = new random(); int notificationid = r.nextint(); notificationintent.putextra("n_id", notificationid); pendingintent contentintent = pendingintent.getactivity(this, notificationid, notificationintent, pendingintent.flag_update_current); notification.defaults |= notification.default_sound; notification.setlatesteventinfo(this, "party", "welcome!", contentintent); mnotificationmanager.notify(notificationid, notification); }
you can cancel notification in youractivity this:
public class youractivity extends activity{ @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.your_activity); int notificationid = getintent().getintextra("n_id", -1); if (notificationid!=-1) { notificationmanager mnotificationmanager = (notificationmanager) getsystemservice(context.notification_service); mnotificationmanager.cancel(notificationid); } } }
Comments
Post a Comment