Flutter android alarm manager plus works in emulator periodically but not working in real device?

392 Views Asked by At

I am using flutter android alarm manager package to get local notifications periodically. It's working perfectly in the emulator but when I am generating an apk file and installing the app in a real android device through that apk file it's not showing any notification. So, could anyone please help me sharing your precious experience. Thanks in advance! Here you go with my code -

Future<void> notify() async {

  try {
    await Quote.saveNewQuote();
  } catch (e) {
    print(e.toString());
  }

  AwesomeNotifications().createNotification(
      content: NotificationContent(
        id: 1,
        channelKey: 'basic_notification',
        title: 'Notification',
        body: 'Android alarm manager periodical notification',
      ));
  
 // await Quote.notifyLastQuote();
}

void main() async {

  WidgetsFlutterBinding.ensureInitialized();
  await AndroidAlarmManager.initialize();
  await AwesomeNotifications().initialize('resource://drawable/fitjerk_logo',
      [
        NotificationChannel(
            channelKey: 'basic_notification',
            channelName: 'FitJerk Motivation',
            channelDescription: "FitJerk Today Notification ",
            defaultColor: primaryDeepColor,
            importance: NotificationImportance.High,
            ledColor: Colors.white,
            playSound: true,
            enableLights: true,
            enableVibration: true
        )
      ]);

  await AndroidAlarmManager.periodic(const Duration(hours: 24), 1, notify,

      ///TODO: here will set startAt time///
      startAt: DateTime(DateTime.now().year, DateTime.now().month, DateTime.now().day, 8, 30),
      exact: true, wakeup: true, allowWhileIdle: true, rescheduleOnReboot: true);

And here is my AndroidMenifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.example.fit_jerk">
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <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"/>
    <uses-permission android:name="com.google.android.gms.permission.AD_ID" tools:node="remove"/>
   <application

        android:label="FitJerk"
        android:name="${applicationName}"
        android:icon="@mipmap/ic_launcher"
       tools:ignore="ExtraText">
<!--       this portion is for android alarm plus-->
<!--        android:name = "io.flutter.app.FlutterApplication"-->
       <service
           android:name="dev.fluttercommunity.plus.androidalarmmanager.AlarmService"
           android:permission="android.permission.BIND_JOB_SERVICE"
           android:exported="false"
           tools:ignore="MissingClass" />
       <receiver
           android:name="dev.fluttercommunity.plus.androidalarmmanager.AlarmBroadcastReceiver"
           android:exported="false"
           tools:ignore="MissingClass" />
       <receiver
           android:name="dev.fluttercommunity.plus.androidalarmmanager.RebootBroadcastReceiver"
           android:enabled="false"
           android:exported="false"
           tools:ignore="MissingClass">
           <intent-filter>
               <action android:name="android.intent.action.BOOT_COMPLETED" />
           </intent-filter>
       </receiver>

        <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>
        <!-- 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" />

       <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>
       <meta-data android:name="com.facebook.sdk.ClientToken" android:value="@string/facebook_client_token"/>



       <activity android:name="com.facebook.FacebookActivity"
           android:configChanges=
               "keyboard|keyboardHidden|screenLayout|screenSize|orientation"
           android:label="@string/app_name"
           tools:ignore="MissingClass" />
       <activity
           android:name="com.facebook.CustomTabActivity"
           android:exported="true"
           tools:ignore="MissingClass">
           <intent-filter>
               <action android:name="android.intent.action.VIEW" />
               <category android:name="android.intent.category.DEFAULT" />
               <category android:name="android.intent.category.BROWSABLE" />
               <data android:scheme="@string/fb_login_protocol_scheme" />
           </intent-filter>
       </activity>



       <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="ca-app-pub-8656344449994415~3632328521"/>
    </application>
</manifest>
0

There are 0 best solutions below