gpt4 book ai didi

android - 推送通知kotlin

转载 作者:行者123 更新时间:2023-12-02 13:35:59 28 4
gpt4 key购买 nike

如何解决呢?
有什么想法吗?
谢谢你的帮助

private var notificationManager: NotificationManager? = null

......
problem Classifier 'NotificationManager' does not have a companion object, and thus must be initialized here

代码行->
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);


override fun onChildAdded(ds: DataSnapshot, prevChildKey: String?) {

Log.i(TAG, " child added")
if(markers.size == 0) {
pushIssueMarker(ds)
}
builder.setSmallIcon(R.mipmap.ic_launcher);
builder.setContentTitle("Firebase Push Notification");
builder.setContentText("Hello this is a test Firebase notification, a new database child has been added");
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager?.notify(1, builder.build());
}

最佳答案

您正在用Kotlin进行编码。因此,其对象创建与JAVA不同。

更改您的下一行

NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

到这条线
val notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager

关于android - 推送通知kotlin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57229053/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com