0

I'm making alarm app using android alarm manager in flutter.

Alarm is correctly working by using this hack. But there is problem that some device doesn't launch my app when alarm is fired on background.

For example, When set the alarm and click home button, just callback function has been called, app hasn't been launch.

Using Samsung s8, app is launched when alarm is fired. But emulator sdk_gphone_x86_arm and Samsung s10 doesn't launch app.

I want to make google's alarm app, but some device doesn't launch app. what is problem?

MaNDOOoo
  • 1,347
  • 1
  • 5
  • 19
  • You can launch your app from callback using this package: https://pub.dev/packages/intent – Dmytro Rostopira Dec 28 '20 at 10:16
  • @DimaRostopira Thank you for comment! I've searched about `intent`, but I didn't know how to use this. So would you show me some example? – MaNDOOoo Dec 28 '20 at 11:57
  • I think [android 10.0 version prevent to active intent service in background](https://stackoverflow.com/questions/59419653/cannot-start-activity-background-in-android-10-android-q). – MaNDOOoo Dec 29 '20 at 02:12

1 Answers1

1

Finally, I find solution using few days!!

CAUSE:

Android 10.0(Q) prevent to start Active in background. You can see document here.

SOLUTION:

  1. Add this in Manifest <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
  2. Allow permission at your flutter app
    (Route: Setting -> Apps & notifications -> Your flutter app -> Advanced -> Display over other apps)

REFERENCE:

cannot start activity background in android 10, android Q

MaNDOOoo
  • 1,347
  • 1
  • 5
  • 19
  • Can you post a complete example? – Bassel Alkhateeb Apr 20 '21 at 23:47
  • 1
    @Bassel Alkhateeb I use [flutter-permission-handler](https://github.com/Baseflow/flutter-permission-handler), but there is not system alert window permission. So I forked [repo](https://github.com/jja08111/flutter-permission-handler) from [this PR](https://github.com/Baseflow/flutter-permission-handler/pull/389). – MaNDOOoo Apr 21 '21 at 02:23
  • @MaNDOOoo hi, can you please post an example of how you have achieved launching your app from the background using android alarm manager plugin? I'm really struggling to achieve this. – Chris Mar 08 '22 at 10:22
  • @Chris I achieved this by using the `BroadcastReceiver` of the `android_alarm_manager` plugin. Here is the [code](https://github.com/jja08111/plus_plugins/blob/main/packages/android_alarm_manager_plus/android/src/main/java/dev/fluttercommunity/plus/androidalarmmanager/AlarmBroadcastReceiver.java) that I used for my alarm app. Hope this helps. – MaNDOOoo Mar 08 '22 at 11:52
  • @MaNDOOoo thanks for the reply. I don't suppose you'd be willing to share the code for your alarm app to demonstrate how you've implemented this? – Chris Mar 08 '22 at 12:04
  • @MaNDOOoo, nevermind! I just tried it on my device and it unlocked it :D Now I just need to bring the app to front/open it :D Thanks! – Chris Mar 08 '22 at 12:11
  • @MaNDOOoo actually, it would be really helpful if I could see what you've done because something isn't working right. – Chris Mar 08 '22 at 13:03
  • @Chris Unfortunately, I can't share my app code but here is a [greate alarm app example](https://github.com/geisterfurz007/random-alarm) that I referenced to make my alarm app. And here is an article that I wrote for guiding to make alarm app in Korean. – MaNDOOoo Mar 08 '22 at 14:39
  • No problem, and thanks for your help. The only thing I'm having trouble with is getting the app to come to the foreground when the alarm triggers. – Chris Mar 08 '22 at 16:13
  • @Chris There are two points for launching the app to the foreground. First, [edit the `AlarmBroadcastReceiver` of the `android_alarm_plugin`](https://github.com/flutter/flutter/issues/30555#issuecomment-501597824). Second, set the flags like [here](https://github.com/geisterfurz007/random-alarm/blob/master/android/app/src/main/kotlin/io/github/geisterfurz007/playground/MainActivity.kt) to show the app at the lock screen. (And here is [my article](https://jja08111.github.io/flutter/flutter-alarm-app/) that I missed linking to the previous comment.) – MaNDOOoo Mar 09 '22 at 02:24