2
我正在嘗試使用目標API 26和最小API 19建立通知。 我無法獲取將Channel ID作爲第二個參數的NotificationCompat.Builder構造函數。無法獲取NotificationCompat.Builder 2參數構造函數
這是我的通知類到目前爲止。 在最底部我想獲得通知生成器。
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. +以獲得新的構造函數。 –