问题描述:在创建NotificationCompat时遇到问题。
解决方案:
implementation 'com.android.support:support-compat:28.0.0'
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.notification_icon)
.setContentTitle("Notification Title")
.setContentText("Notification Content");
<uses-permission android:name="android.permission.VIBRATE" />
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel("channel_id", "Channel Name", NotificationManager.IMPORTANCE_DEFAULT);
NotificationManager notificationManager = getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel);
builder.setChannelId(channel.getId());
}
Notification notification = builder.build();
以上是针对问题的一般解决方案,如果问题仍然存在,请提供更多详细信息以便进一步排查和解决。
领取专属 10元无门槛券
手把手带您无忧上云