【发布时间】:2017-10-04 20:30:33
【问题描述】:
我正在尝试使用 Target API 26 和 min API 19 构建通知。 我无法获得将 Channel ID 作为第二个参数的 NotificationCompat.Builder 构造函数。
到目前为止,这是我的通知类。 在最底部,我想获得通知生成器。
public class NotificationHelper extends ContextWrapper {
private NotificationManager notificationManager;
public NotificationHelper(Context base) {
super(base);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
createChannel();
}
}
@TargetApi(Build.VERSION_CODES.O)
public void createChannel() {
NotificationChannel channel1 = new NotificationChannel("channel1", "Channel one", NotificationManager.IMPORTANCE_DEFAULT);
channel1.enableLights(true);
channel1.enableVibration(true);
channel1.setLightColor(R.color.colorPrimary);
channel1.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
getManager().createNotificationChannel(channel1);
}
public NotificationManager getManager() {
if (notificationManager == null) {
notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
}
return notificationManager;
}
public NotificationCompat.Builder() {
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(getApplicationContext(), "channel1");
}
}
【问题讨论】:
-
请在此处发布您的
build.gradle文件。 -
我正在尝试,但格式不正确。我们在寻找什么?
-
您必须将支持库设置为 26.+ 才能拥有新的构造函数。
-
谢谢,它是在 26.0.0-alpha1,但 26.0.1 成功了
标签: java android android-notifications