android通知
在sdk版本为25或25之前通知方法有变,《android第一行代码》代码跑不通,修改如下
public void onClick(View view)
{
String description = "text";
int important = NotificationManager.IMPORTANCE_LOW;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O)
{
NotificationChannel notificationChannel = new NotificationChannel("001",description,important);
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
manager.createNotificationChannel(notificationChannel);
Notification notification = new NotificationCompat.Builder(this,"001")
.setContentTitle(" title")
.setContentText("content text")
.setWhen(System.currentTimeMillis())
.setSmallIcon(R.mipmap.ic_launcher)
.setLargeIcon(BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher))
.build();
manager.notify(1,notification);
}
else
{
NotificationManager manager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
Notification notification = new NotificationCompat.Builder(MainActivity.this)
.setContentTitle(" title")
.setContentText("content text")
.setSmallIcon(R.mipmap.ic_launcher)
.build();
manager.notify(1,notification);
}
}
Android通知兼容适配

被折叠的 条评论
为什么被折叠?



