I’m trying to use android alarm manager plus in my flutter app to schedule some local notifications. I started with simple AndroidAlarmManager.oneShot(..) function. And I"m calling intialize function in main method.
void main() async{
WidgetsFlutterBinding.ensureInitialized();
await AndroidAlarmManager.initialize();
runApp(const MyApp());
}
that await AndroidAlarmManager.initialize();
cause the error. Error is
E/flutter (10486): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: MissingPluginException(No implementation found for method AlarmService.start on channel dev.fluttercommunity.plus/android_alarm_manager)
So I’m as I read some other issues, the problem is with pluginregistrar is not registering AlarmService. So I have to add a native code to Application file. But my project doesn’t have Application.java file.
All I have is
1.flutter_project_rootandroidappsrcmainjavaioflutterpluginsGeneratedPluginRegistrant.java
@Keep
public final class GeneratedPluginRegistrant {
private static final String TAG = "GeneratedPluginRegistrant";
public static void registerWith(@NonNull FlutterEngine flutterEngine) {
try {
flutterEngine.getPlugins().add(new dev.fluttercommunity.plus.androidalarmmanager.AndroidAlarmManagerPlugin());
} catch(Exception e) {
Log.e(TAG, "Error registering plugin android_alarm_manager_plus, dev.fluttercommunity.plus.androidalarmmanager.AndroidAlarmManagerPlugin", e);
}
}
}
2.flutter_rootandroidappsrcmainkotlincomexamplesnooze_testMainActivity.kt
import io.flutter.embedding.android.FlutterActivity
class MainActivity: FlutterActivity() {
}
I don’t know native code. How should fix this?
2
Answers
It worked without changing anything after I cold booted the emulator.
you have to put the required file in
AndroidMenifest.xml
location project -> android->app->src->main->
For more detail refer: https://pub.dev/packages/android_alarm_manager_plus
After update manifest file once uninstall and install app from device