文章目录
1.弃用构造函数2.新方法使用参考链接可用构造函数
3.结果
1.弃用构造函数
@Deprecated
public Builder(android
.content
.Context context
)
2.新方法使用
参考链接
参考链接:https://www.cnblogs.com/chunshu/p/10317960.html
可用构造函数
public Builder(@NonNull android
.content
.Context context
,
@NonNull String channelId
)
@Override
public int onStartCommand(Intent intent
, int flags
, int startId
) {
Notification noti
= new NotificationCompat.Builder(this, "channelid1")
.setContentTitle("标题")
.setContentText("Hello Content.")
.setSmallIcon(R
.drawable
.ic_launcher_foreground
)
.build();
manager
= (NotificationManager
) getSystemService(NOTIFICATION_SERVICE
);
if(Build
.VERSION
.SDK_INT
>= android
.os
.Build
.VERSION_CODES
.O
){
NotificationChannel notificationChannel
= new NotificationChannel("channelid1","channelname",NotificationManager
.IMPORTANCE_HIGH
);
manager
.createNotificationChannel(notificationChannel
);
}
manager
.notify(1, noti
);
return super.onStartCommand(intent
, flags
, startId
);
}
3.结果