我正在尝试创建一个通知系统作为 Recycerview 值更改。我在我的onbind
方法中编写了下面的代码。它正在创建通知但问题是每次都创建通知虽然我需要根据条件创建它if(tBii>0 && notify>0)
如果不满足条件如何停止通知
public void bind(final Book_Activebid book, String key){
int tBii=Integer.parseInt(book.gettBii());
int notify=Integer.parseInt(book.getNotify());
if(tBii>0 && notify>0){
String last_1=book.getLst_1();
String last_2=book.getLst_2();
String last_3=book.getLst_3();
if(last_1!=null && last_1!=null && last_1!=null){
notifyThis("Notification", last_1,last_2+" Has "+last_3);
}
}
}
这是我的 notifyThis 方法
public void notifyThis(String title,String subtext,String message) {
NotificationCompat.Builder b = new NotificationCompat.Builder(this.mContext);
b.setAutoCancel(true)
.setDefaults(NotificationCompat.DEFAULT_ALL)
.setWhen(System.currentTimeMillis())
.setSmallIcon(R.drawable.flag_bulgaria)
.setTicker("Notification")
.setContentTitle(title)
.setSubText(subtext)
.setVibrate(new long[] { 1000, 1000, 1000, 1000, 1000 })
.setLights(Color.RED, 3000, 3000)
.setContentText(message)
.setContentInfo("Bii");
Intent notificationIntent = new Intent(mContext,MainActivity.class);
PendingIntent conPendingIntent = PendingIntent.getActivity(mContext,0,notificationIntent,PendingIntent.FLAG_UPDATE_CURRENT);
b.setContentIntent(conPendingIntent);
NotificationManager nm = (NotificationManager) this.mContext.getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(1, b.build());
}
为什么 book 变量是 final 的?
最终变量不能重新赋值,所以它总是显示通知
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句