简体   繁体   English

我想在执行if块时向用户(移动应用程序)发出通知。 此代码无效,我的代码有什么问题?

[英]I want to give notification to the user (mobile application) when the if block is execute. this code doesn't work, what is wrong with my code?

if (200 <= intId && intId <= 250) {//if there is some Thondering give a alert

                    Notification noti = new Notification.Builder(MainActivity.this)
                            .setTicker("Tickertittle")
                            .setContentTitle("ELEKTRA WEATHER ALERT")
                            .setContentText("TURN OFF the multi plug for lighting safety")
                            .setContentIntent();

                       noti.flags = Notification.FLAG_AUTO_CANCEL;
                       NotificationManager nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
                       nm.notify(0,noti);

                }

If you don't want to have an Intent for the Notification, you should create a dummy one 如果您不想收到通知的意图,则应创建一个虚拟通知

PendingIntent dummyIntent = PendingIntent.getActivity(
   getApplicationContext(),
   0,
   new Intent(),
   PendingIntent.FLAG_UPDATE_CURRENT);

and then call setContentIntent(dummyIntent) 然后调用setContentIntent(dummyIntent)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM