Issue
I am trying to use the android_alarm_manager_plus package to schedule background tasks in flutter. In their documentation, they have added the Application
class code for JAVA, which is as follows -
public class Application extends FlutterApplication implements PluginRegistrantCallback {
@Override
public void onCreate() {
super.onCreate();
AlarmService.setPluginRegistrant(this);
}
@Override
public void registerWith(PluginRegistry registry) {
GeneratedPluginRegistrant.registerWith(registry);
}
}
But I'm working on a kotlin based project (without any knowledge of kotlin, I may add) and there is no documentation for this. I tried writing the kotlin counterpart to this code myself, but I'm still facing errors.
My Application.kt
file -
package com.example.my_app;
import io.flutter.app.FlutterApplication;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback;
import io.flutter.plugins.GeneratedPluginRegistrant;
import io.flutter.plugins.AndroidAlarmManager.AlarmService;
class Application : FlutterApplication(), PluginRegistry.PluginRegistrantCallback {
override fun onCreate() {
super.onCreate()
AlarmService.setPluginRegistrant(this);
}
override fun registerWith(registry: PluginRegistry?) {
registry?.registrarFor("GeneratedPluginRegistrant");
}
}
The errors -
Application.kt: (7, 27): Unresolved reference: AndroidAlarmManager
Application.kt: (15, 9): Unresolved reference: AlarmService
Solution
You do not need to add this Java/Kotlin code. That's for the old Android embedding. Note the "DEPRECATED" here in the title: https://github.com/fluttercommunity/plus_plugins/tree/main/packages/android_alarm_manager_plus#flutter-android-embedding-v1-deprecated
Answered By - Gazihan Alankus
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.