'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
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
<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()
}
}
Solution 1:[1]
you can get getSystemService from context
change your code
from:
val notificationManager: NotificationManager = getSystemService(context.NOTIFICATION_SERVICE) as NotificationManager
to:
val notificationManager: NotificationManager = context.getSystemService(context.NOTIFICATION_SERVICE) as NotificationManager
where context is context = flutterPluginBinding.getApplicationContext();
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Skandar Munir |
