急急急!求助各位大神,我的Notification怎么都没有办法显示,就一个最简单的显示都出不来,控制台也没有出现任何错误,下面是我的源代码,小白求教各位大神!!!
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String id = "my_channel_01";
String name="我是渠道名字";
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Log.v("MainActivity","12312");
Notification notification = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel mChannel = new NotificationChannel(id, name, NotificationManager.IMPORTANCE_LOW);
Toast.makeText(MainActivity.this, mChannel.toString(), Toast.LENGTH_SHORT).show();
manager.createNotificationChannel(mChannel);
notification = new Notification.Builder(MainActivity.this,null)
.setChannelId(id)
.setContentTitle("5 new messages")
.setContentText("hahaha")
.setSmallIcon(R.mipmap.ic_launcher).build();
} else {
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(MainActivity.this,null)
.setContentTitle("5 new messages")
.setContentText("hahaha")
.setSmallIcon(R.mipmap.ic_launcher)
.setOngoing(true);
notification = notificationBuilder.build();
}
manager.notify(111123, notification);
}
});
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String id = "my_channel_01";
String name="我是渠道名字";
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Log.v("MainActivity","12312");
Notification notification = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel mChannel = new NotificationChannel(id, name, NotificationManager.IMPORTANCE_LOW);
Toast.makeText(MainActivity.this, mChannel.toString(), Toast.LENGTH_SHORT).show();
manager.createNotificationChannel(mChannel);
notification = new Notification.Builder(MainActivity.this,null)
.setChannelId(id)
.setContentTitle("5 new messages")
.setContentText("hahaha")
.setSmallIcon(R.mipmap.ic_launcher).build();
} else {
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(MainActivity.this,null)
.setContentTitle("5 new messages")
.setContentText("hahaha")
.setSmallIcon(R.mipmap.ic_launcher)
.setOngoing(true);
notification = notificationBuilder.build();
}
manager.notify(111123, notification);
}
});
解决方案 »
- android开发环境搭建。求入门。
- gridview动态加载图片
- 怎样取得android短信数据库中发件人收件人的名字?
- 求几个国外的android开源网站????????
- 关于 Handler.removeCallbacks ,求真相
- 求android入门到晋级的教程
- 请教:能否不用界面在手机上运行一个TcpClient或者TcpServer程序?
- android调用系统界面发送彩信
- 安卓写出来的程序太卡
- 关于使用ExpandListView自定义展开关闭的问题
- 安卓音乐播放器
- 一直出现这个#include expects "FILENAME" or <FILENAME>,大佬求帮助呀,小白真的看不懂
看看权限是否开了