alarm icon indicating copy to clipboard operation
alarm copied to clipboard

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

Open synstin opened this issue 8 months ago • 26 comments

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)

synstin avatar Dec 22 '23 01:12 synstin

Hi @synstin

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

gdelataillade avatar Dec 22 '23 16:12 gdelataillade

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

synstin avatar Dec 23 '23 07:12 synstin

Hi @synstin

Did you gave permission to your app to show notifications ?

gdelataillade avatar Dec 23 '23 14:12 gdelataillade

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

synstin avatar Dec 24 '23 02:12 synstin

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.

gdelataillade avatar Dec 24 '23 15:12 gdelataillade

@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 avatar Dec 25 '23 09:12 synstin

@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 avatar Dec 25 '23 09:12 synstin

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

synstin avatar Dec 25 '23 11:12 synstin

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

EricssonXD avatar Dec 26 '23 04:12 EricssonXD

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 avatar Dec 28 '23 10:12 Prashant-Mohania

I'm not getting push notification when alarm is ringing

AwaisQazii avatar Dec 29 '23 13:12 AwaisQazii

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 avatar Jan 02 '24 10:01 gdelataillade

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

gdelataillade avatar Jan 11 '24 15:01 gdelataillade

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

synstin avatar Jan 12 '24 01:01 synstin

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

gdelataillade avatar Jan 12 '24 13:01 gdelataillade

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?

Rest00rer avatar Feb 03 '24 22:02 Rest00rer

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 avatar Feb 06 '24 07:02 Flash0509

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 avatar Feb 06 '24 07:02 Flash0509

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.

  • What went wrong: Execution failed for task ':app:minifyReleaseWithR8'.

A failure occurred while executing com.android.build.gradle.internal.tasks.R8Task$R8Runnable Compilation failed to complete, origin: C:\scr\flutter\projects\smartabox_app\build\alarm\intermediates\runtime_library_classes_jar\release\classes.jar:com/example/smartabox_app/BuildConfig.class

  • Try:

Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.``

Flash0509 avatar Feb 06 '24 08:02 Flash0509

Hi Gautier,

any new idea or comments related to my last posts?

Flash0509 avatar Feb 13 '24 22:02 Flash0509

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 !

gdelataillade avatar Feb 13 '24 22:02 gdelataillade

Hi @gdelataillade

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

hoangan avatar Feb 20 '24 11:02 hoangan

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 avatar Feb 20 '24 15:02 Flash0509

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.

Flash0509 avatar Feb 21 '24 11:02 Flash0509

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

gdelataillade avatar Mar 11 '24 17:03 gdelataillade

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 avatar Apr 12 '24 15:04 gdelataillade