急急急!求助各位大神,我的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);
}
});
uj5u.com熱心網友回復:
NotificationManagerCompat.from(this).areNotificationsEnabled();看看權限是否開了
uj5u.com熱心網友回復:
8.0的系統吧,請移步https://blog.csdn.net/qq_35749683/article/details/80451791轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/151223.html
標籤:Android
上一篇:想匯入別人的專案看效果,結果一直module not specified
下一篇:Android跳轉問題
