找不到方法createNotificationChannel(NotificationChannel)

时间:2018-01-12 18:04:42

标签: android

我尝试使用Android Oreo(SDK 27)处理通知。

以下是我创建NotificationChannel的代码:

NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
// .. building mChannel, the NotificationChannel instance
notificationManager.createNotificationChannel(mChannel);

Android Studio告诉您

Error:(67, 32) error: cannot find symbol method createNotificationChannel(NotificationChannel)

我依赖support-compat:27.0.0设置到我的core / build.gradle文件中:

compile 'com.android.support:support-compat:27.0.0'

1 个答案:

答案 0 :(得分:13)

createNotificationChannel()上没有NotificationManagerCompat方法。您必须使用原生NotificationManager