在不同的手机上,通知的行为可能会有所不同。为了确保通知在所有手机上都能正常工作,建议使用Android的通知管理器。以下是一个示例代码,用于创建并发送通知:
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.notification_icon)
.setContentTitle("My notification")
.setContentText("Hello World!")
.setPriority(NotificationCompat.PRIORITY_DEFAULT);
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
// notificationId is a unique int for each notification that you must define
notificationManager.notify(notificationId, builder.build());
该示例使用notificationCompat库构建通知,并使用NotificationManagerCompat
处理通知。这将确保通知在所有Android设备上都能正常工作。
下一篇:不同首字母的电话号码验证