skip to Main Content

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


  1. Chosen as BEST ANSWER

    It worked without changing anything after I cold booted the emulator.


  2. you have to put the required file in AndroidMenifest.xml
    location project -> android->app->src->main->

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.tmdp_getx_mvc">
    
        <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
        <uses-permission android:name="android.permission.WAKE_LOCK"/>
    <!-- For apps with targetSDK=31 (Android 12) -->
        <uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM"/>
       <application
            android:label="tmdp_getx_mvc"
            android:name="${applicationName}"
            android:icon="@mipmap/ic_launcher">
            <activity
                android:name=".MainActivity"
                android:exported="true"
                android:launchMode="singleTop"
                android:theme="@style/LaunchTheme"
                android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
                android:hardwareAccelerated="true"
                android:windowSoftInputMode="adjustResize">
                <!-- Specifies an Android theme to apply to this Activity as soon as
                     the Android process has started. This theme is visible to the user
                     while the Flutter UI initializes. After that, this theme continues
                     to determine the Window background behind the Flutter UI. -->
                <meta-data
                  android:name="io.flutter.embedding.android.NormalTheme"
                  android:resource="@style/NormalTheme"
                  />
                  
                <intent-filter>
                    <action android:name="android.intent.action.MAIN"/>
                    <category android:name="android.intent.category.LAUNCHER"/>
                </intent-filter>
            </activity>
            <service
                android:name="dev.fluttercommunity.plus.androidalarmmanager.AlarmService"
                android:permission="android.permission.BIND_JOB_SERVICE"
                android:exported="false"/>
            <receiver
                android:name="dev.fluttercommunity.plus.androidalarmmanager.AlarmBroadcastReceiver"
                android:exported="false"/>
            <receiver
                android:name="dev.fluttercommunity.plus.androidalarmmanager.RebootBroadcastReceiver"
                android:enabled="false"
                android:exported="false">
                <intent-filter>
                    <action android:name="android.intent.action.BOOT_COMPLETED" />
                </intent-filter>
            </receiver>
            <!-- Don't delete the meta-data below.
                 This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
            <meta-data
                android:name="flutterEmbedding"
                android:value="2" />
        </application>
    </manifest>
    

    For more detail refer: https://pub.dev/packages/android_alarm_manager_plus
    After update manifest file once uninstall and install app from device

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search