当我尝试将我的通知代码设置为按钮时
它总是给我这部分的错误
NotificationCompat.Builder mBuilder =新NotificationCompat.Builder(this)
[[构造函数NotificationCompat.Builder(new VIEw.OnClickListener(){})未定义]]
我该如何解决这个问题?
button button9= (button) findVIEwByID(R.ID.button9); button9.setonClickListener(new VIEw.OnClickListener(){ public voID onClick(VIEw arg0) { ///////////My Notification////////////////////////// NotificationCompat.Builder mBuilder =new NotificationCompat.Builder(this) .setSmallicon(R.drawable.notification_icon) .setContentTitle("I'm astm loooooooool") .setContentText("Hello baby to my world!"); // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(this, MainActivity.class); // The stack builder object will contain an artificial back stack for the // started Activity. // This ensures that navigating backward from the Activity leads out of // your application to the Home screen. TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); // Adds the back stack for the Intent (but not the Intent itself) (ResultActivity) stackBuilder.addParentStack(MainActivity.class); // Adds the Intent that starts the Activity to the top of the stack stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); notificationmanager mnotificationmanager=(notificationmanager) getSystemService(Context.NOTIFICATION_SERVICE); int mID = 0; // mID allows you to update the notification later on. mnotificationmanager.notify(mID, mBuilder.build()); ///////////End Notification////////////////////////// } });
解决方法:
谢谢你们对我的帮助[[没有人给我任何答案looooooool]]
我自己得到答案
只需将NotificationCompat.Builder定义为Final即可,效果很好
^ __ ^
///////// my Nine button (set Notification) ////////// final NotificationCompat.Builder mBuilder =new NotificationCompat.Builder(this) .setSmallicon(R.drawable.notification_icon) .setContentTitle("I'm astm loooooooool") .setContentText("Hello baby to my world!"); button button9= (button) findVIEwByID(R.ID.button9); final TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); button9.setonClickListener(new VIEw.OnClickListener(){ public voID onClick(VIEw arg0) { ///////////My Notification////////////////////////// // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(); // The stack builder object will contain an artificial back stack for the // started Activity. // This ensures that navigating backward from the Activity leads out of // your application to the Home screen. // Adds the back stack for the Intent (but not the Intent itself) (ResultActivity) stackBuilder.addParentStack(MainActivity.class); // Adds the Intent that starts the Activity to the top of the stack stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); notificationmanager mnotificationmanager=(notificationmanager) getSystemService(Context.NOTIFICATION_SERVICE); int mID = 0; // mID allows you to update the notification later on. mnotificationmanager.notify(mID, mBuilder.build()); ///////////End Notification////////////////////////// } });
总结 以上是内存溢出为你收集整理的android NotificationCompat.Builder未定义全部内容,希望文章能够帮你解决android NotificationCompat.Builder未定义所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)