val but:Button=findViewById(R.id.button) but.setOnClickListener{ val manager=getSystemService(NOTIFICATION_SERVICE) as NotificationManager if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { manager.createNotificationChannel(NotificationChannel("999","vip",NotificationManager.IMPORTANCE_DEFAULT)) } val notification=NotificationCompat.Builder(this,"999") .setContentTitle("efs") .setContentText("adad") .setSmallIcon(R.drawable.ic_launcher_background) .build() manager.notify(1,notification) }
设置一个id为button的按钮,在按钮的监听事件中写入代码(如上),不用改变任何代码,手机即可发送通知。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)