gdelataillade / alarm

A Flutter plugin to easily manage alarms on iOS and Android
https://pub.dev/packages/alarm
MIT License
132 stars 86 forks source link

In version 3.0.0, Android does not receive events on Alarm.ringStream.stream #122

Closed synstin closed 5 months ago

synstin commented 11 months ago

Alarm plugin version 3.0.0

Describe the bug Android does not receive events on Alarm.ringStream.stream No events are received, but the alarm sounds.

IOS is receiving fine, but only Android is experiencing issues. This happens equally in versions 3.0.0 and 3.0.1. 2.2.0 works fine on both IOS and Android.

And on Android, I'll hear the sound in the background, but no push notifications.

Device info I tested it on a real device.

LM-V409N Android 10 (SDK 29)

gdelataillade commented 11 months ago

Hi @synstin

Did you followed the android installation steps in the README ? It could be the reason of your issues.

synstin commented 11 months ago

@gdelataillade Yes I followed all the steps, this is my manifest file.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools">

    <!-- USER PERMISSION -->
    <uses-permission android:name="android.permission.VIBRATE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
    <uses-permission android:name="android.permission.WAKE_LOCK"/>
    <uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM"/>
    <uses-permission android:name="android.permission.USE_EXACT_ALARM"/>
    <uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT"/>
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
    <uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY"/>
    <!-- /USER PERMISSION -->

    <application
            android:label="XX"
            android:name="${applicationName}"
            android:icon="@mipmap/launcher_icon"
            android:requestLegacyExternalStorage="true">

        <!-- ALARM -->
        <service android:name="com.gdelataillade.alarm.services.NotificationOnKillService"/>
        <!-- /ALARM -->

        <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"
                android:showWhenLocked="true"
                android:turnScreenOn="true">

            <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>

        <meta-data
                android:name="flutterEmbedding"
                android:value="2"/>

    </application>

</manifest>
gdelataillade commented 11 months ago

Hi @synstin

Did you gave permission to your app to show notifications ?

synstin commented 11 months ago

@gdelataillade Yes notification permissions are enabled and I even tried it in version 3.0.2, but it only sounds, I don't receive any events from the stream and no push notifications come.

gdelataillade commented 11 months ago

Hi @synstin

That's really weird. Can you double check the installation steps ? Do you have any error logs ? Maybe try to disable your app battery optimizations in your Android settings. Keep me updated.

synstin commented 11 months ago

@gdelataillade

I am currently testing it. First, I double-checked that the battery optimization options and Android settings were fine. The first thing I noticed is that if I set the alarm ID to 0, the push notification does not come. If I set it to a number greater than 0, the push notification comes fine.

synstin commented 11 months ago

@gdelataillade

Sometimes events come into the current stream and sometimes they don't. However, when I do a hot restart, the events come into the stream.

synstin commented 11 months ago

@gdelataillade

I have found the cause. I'm using getx and LazyLoadIndexedStack to handle the routing that way. If I do it that way, no event is received, only if I do a hot reload.

@override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Obx(() {
        return LazyLoadIndexedStack(
          index: controller.currentIndex,
          children: [
            Navigator(
              onGenerateRoute: (_) => GetPageRoute(page: () => ExampleAlarmHomeScreen()),
            ),
            Navigator(
              onGenerateRoute: (_) => GetPageRoute(page: () => const TestPage(), binding: RecommendRoutineBinding()),
            ),
          ],
        );
      }),
    );
  }

However, if I use the home field of GetMaterialApp in the following way, everything works fine.

GetMaterialApp(
  home: const ExampleAlarmHomeScreen(),
);

I really need to use the Navigator-onGenerateRoute method to use LazyLoadIndexedStack, is there a workaround?

EricssonXD commented 11 months ago

I guess you could wrap the entire thing in a base widget, and listen to the alarm on the base widget, and have everything else placed on top of that widget

Prashant-Mohania commented 11 months ago

Is their any way to do this, I am facing the same problem. I am getting a notification and sound but their is not event in ringStream but when i restart the app when alarm is ringing then I am able to get the event in ringStream.

AwaisQazii commented 10 months ago

I'm not getting push notification when alarm is ringing

gdelataillade commented 10 months ago

Is their any way to do this, I am facing the same problem. I am getting a notification and sound but their is not event in ringStream but when i restart the app when alarm is ringing then I am able to get the event in ringStream.

@Prashant-Mohania do you have a similar configuration as @synstin ?

gdelataillade commented 10 months ago

I just released version 3.0.3 with some Android fixes. Let me know if it fixes your issue.

synstin commented 10 months ago

@gdelataillade Thank you. However, I am still not receiving any alarm events.

gdelataillade commented 10 months ago

@synstin Sorry to hear that.

Have you tried to run the example app on your device ? It could help us determine if the issue comes from the device or from your codebase and this way help me identify what I should change in the plugin codebase.

Rest00rer commented 9 months ago

Same problem. It is also present in the new version. In the application from the example, everything works correctly. But in mine the event does not appear in the stream. There are no errors in the console. I checked all the settings several times. Could there be any conflicts with other plugins?

Flash0509 commented 9 months ago

Hi Rest00rer, just so you aren't surprised that I'm now describing my error situation here. Gautier closed my issue #122 and linked it to yours as it deals with the same topic.

Flash0509 commented 9 months ago

After executing the command subscription ??= Alarm.ringStream.stream.listen((event) => checkNextCompartmentTime2()); Subscription has the content "Instance of '_ControllerSubscription'". Thanks to your ingenious way of working with "null-aware assignment operator" (??=)", the stream is not started a second time. So I actually don't need the "await subscription?.cancel();". Isn't that the case? The stream can actually be used as long as the app is running. When setting the alarm settings with Alarm.set, ALARM reports "[Alarm] [DEV] Alarm with id 42 scheduled". So it actually looks quite good from my point of view. Doesn't that already clarify that the stream doesn't get any data when the dateTime is reached and that's the issue?

Flash0509 commented 9 months ago

I share Rest00rer's suspicion, with the possibility of the error being due to another plugin. For me, error #79 occurs again in a similar form, but only with the release build, which perhaps gives a suitable picture of the situation. Debug apk build works.

ERROR: C:\scr\flutter\projects\smartabox_app\build\alarm\intermediates\runtime_library_classes_jar\release\classes.jar: R8: Type com.example.smartabox_app.BuildConfig is defined multiple times: C:\scr\flutter\projects\smartabox_app\build\alarm\intermediates\runtime_library_classes_jar\release\classes.jar:com/example/smartabox_app/BuildConfig.class, C:\scr\flutter\projects\smartabox_app\build\app\intermediates\javac\release\classes\com\example\smartabox_app\BuildConfig.class

FAILURE: Build failed with an exception.

Flash0509 commented 9 months ago

Hi Gautier,

any new idea or comments related to my last posts?

gdelataillade commented 9 months ago

Hi @Flash0509

To be honest I didn't spend a lot of time on this issue yet. I'm focusing on crashes that can occur on iOS, which is a bit more important. However, as soon as I finish with that I will make this issue my priority.

In the meantime, if it's possible, try to remove one by one your app's other plugins. It may help determine which is the one who causes the conflict (if there is really one).

Also try to handle your stream listener in a highest level and not in widgets that rebuild often.

Good luck and I'll keep you updated !

hoangan commented 9 months ago

Hi @gdelataillade

I'm having the same issue with Android, tested on Galaxy S21

Flash0509 commented 9 months ago

Since version 3.0.11 the bug with R8 is fixed, even so the alarm is recognized at time. Alarm.ringStream issue still exists.

Flash0509 commented 9 months ago

If I don't close the stream but just continue using it as long as the app is running, everything works again in my case. In my opinion, the error has now been resolved.

gdelataillade commented 8 months ago

Similar/Duplicated issue: #153 Status: Work in progress

gdelataillade commented 7 months ago

Hi @Flash0509 @hoangan

I just released version 3.1.0. It may fix your issues with the stream. Let me know how it goes.

gdelataillade commented 5 months ago

No response for a while, assuming issue is resolved. Closing it now. Feel free to reopen if needed.

joe6851 commented 5 months ago

有什么办法吗?我也遇到了同样的问题。 我收到了通知和声音,但 ringStream 中没有事件,但当我在闹钟响起时重新启动应用程序时,我能够在 ringStream 中获取事件。我也遇到同样的问题