[英]Flutter Custom Notification Application.kt: Unresolved reference
Im new to flutter, I want to have custom ringtone notifications, flutter version is 2.8, I found some tutorials talk about creating application.kt in kotlin folder same where locate mainactivity file, save wave file in the resource folder for android and in runner for ios, all I found just to have the below code in Application file and modify the AndroidMainifest file, this was working with me, but I need to update flutter from old version to the current one, after I update it, the app stop working because of the Application file returns the error below, what can I do to let this works again, sorry for my basic language, hopefully you have a clear solution for this issue,thank you Im new to flutter, I want to have custom ringtone notifications, flutter version is 2.8, I found some tutorials talk about creating application.kt in kotlin folder same where locate mainactivity file, save wave file in the resource folder for android and in runner for ios,我发现只是在应用程序文件中有以下代码并修改 AndroidMainifest 文件,这对我有用,但我需要将 flutter 从旧版本更新到当前版本,更新后,应用程序停止工作,因为应用程序文件返回以下错误,我该怎么做才能让它再次工作,对不起我的基本语言,希望您对此问题有明确的解决方案,谢谢
Error错误
/android/app/src/main/kotlin/com/foodeasy/merchant/Application.kt: (7, 31): Unresolved reference: firebasemessaging
e: /app/src/main/kotlin/com/foodeasy/merchant/Application.kt: (19, 5): Class 'Application' is not abstract and does not implement abstract member public abstract fun registerWith(p0: PluginRegistry!): Unit defined in io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback
AndroidMainifest Android主程序
<application
android:name=".Application"
android:label="myapp"
android:requestLegacyExternalStorage="true"
android:usesCleartextTraffic="true"
android:icon="@mipmap/ic_launcher">
package com.*****.****
import io.flutter.app.FlutterApplication
import io.flutter.plugin.common.PluginRegistry
import io.flutter.plugins.GeneratedPluginRegistrant
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService
import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.Context
import android.media.AudioAttributes
import android.net.Uri
import android.os.Build
import android.util.Log
class Application : FlutterApplication(), PluginRegistrantCallback {
private fun createChannel(){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val sound = Uri.parse("android.resource://" + applicationContext.packageName + "/raw/" + R.raw.ntf)
// Create the NotificationChannel
val channel = NotificationChannel("mychannel", "default", NotificationManager.IMPORTANCE_HIGH)
val audioAttributes = AudioAttributes.Builder()
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.setUsage(AudioAttributes.USAGE_ALARM)
.build()
channel.setSound(sound, audioAttributes)
val notificationManager: NotificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.createNotificationChannel(channel)
}
}
override fun onCreate() {
super.onCreate()
}
}
you can get getSystemService
from context
change your code您可以从context
中获取getSystemService
更改您的代码
from:从:
val notificationManager: NotificationManager = getSystemService(context.NOTIFICATION_SERVICE) as NotificationManager val notificationManager: NotificationManager = getSystemService(context.NOTIFICATION_SERVICE) as NotificationManager
to:至:
val notificationManager: NotificationManager = context.getSystemService(context.NOTIFICATION_SERVICE) as NotificationManager val notificationManager: NotificationManager = context.getSystemService(context.NOTIFICATION_SERVICE) 作为 NotificationManager
where context is context = flutterPluginBinding.getApplicationContext();
其中上下文是context = flutterPluginBinding.getApplicationContext();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.