我正在使用此代码生成推送通知
public class createNotification {
private Context context;
String CHANNEL_ID = "my_channel_01";
int NOTIFICATION_ID = 1;
public createNotification(Context context, String title, String body) {
this.context=context;
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
String CHANNEL_ID = "my_channel_01";
CharSequence name = "my_channel";
String Description = "This is my channel";
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID, name, importance);
mChannel.setDescription(Description);
mChannel.enableLights(true);
notificationManager.createNotificationChannel(mChannel);
}
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_ID)
.setVibrate(new long[]{500, 500})
.setSmallIcon(R.drawable.my_app_icon)
.setContentTitle(title)
.setPriority(Notification.PRIORITY_MAX)
.setContentText(body);
notificationManager.notify(NOTIFICATION_ID, builder.build());
NOTIFICATION_ID++;
}
}
抬头通知显示在Android 7真实设备上,但不显示在Android 5上,我仅得到图标和振动。我在this question中尝试了解决方案,但对我没有用。如何编辑此代码以在Android 5上显示Hedas-Up通知?