簡體   English   中英

推送通知kotlin

[英]Push Notification kotlin

如何解決呢? 有什么想法嗎? 謝謝你的幫助

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

您不需要分成兩行,可以輕松地將其初始化為

val mNotificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM