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);
}
}
版权声明:本文为doubleintfloat原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。