0

I was doing a clock app on flutter, i implemented a clock, a stopwatch, a timer and an alarm

everything was going good, it works, but i just thinked that it would be better if i open the app and not just make a notification arrive, how should i do this?

  • have you tried using a `PendingIntent` ? – Shark Nov 12 '20 at 17:04
  • Mhh nope, can u say more please? – Exodia but better Nov 12 '20 at 17:17
  • Here's [link1](https://stackoverflow.com/questions/2808796/what-is-an-android-pendingintent) and here's [link2](https://developer.android.com/reference/android/app/PendingIntent) you'll probably want to look into the [getActivity()](https://developer.android.com/reference/android/app/PendingIntent#getActivity(android.content.Context,%20int,%20android.content.Intent,%20int)) portion of it – Shark Nov 12 '20 at 17:23
  • Oh so i should open it from native code using a background service? – Exodia but better Nov 12 '20 at 17:48
  • That's up to you. But for all intents and purposes, the `PendingIntent` is the cleanest programatic way to open up your app if it's been in background or not started (yet) at all. If the alarm is "making the notification appear" you can also make the app open up instead of posting the notification by using an explicit pending intent. – Shark Nov 12 '20 at 17:52
  • However, i still don't quite know how this actually applies to iOS; or how their handling would be done in Dart. I'm just covering the android part, still being somewhat fresh with flutter. So I too would be interested in whether a pending intent solves this, and works on both android and iOS. if you make it work - do post an answer please :) – Shark Nov 12 '20 at 17:55
  • [this](https://stackoverflow.com/questions/55694333/flutter-pendingintents-not-received-when-code-is-executed-through-flutter) answer suggest it should work though. Just might not be doable through only dart (i wouldn't know yet) – Shark Nov 12 '20 at 17:58
  • Ok thinking about it is better if i just use alarm manager and just schedule a timer, but, if i use runApp(App()); it does nothing and doesnt open the app, so i dont know how to do this... i searched a bit and didnt find anything about opening an app that isnt opened with flutter, i can even call a native method, but i neither know how to open the app from kotlin, any idea? – Exodia but better Nov 12 '20 at 17:58
  • oh sure i will make a post with the answer – Exodia but better Nov 12 '20 at 17:59
  • PendingIntent should do the trick for the android part of it. regardless of kotlin/java. How (and whether) it will work on iOS is a different story though :D But both java/kotlin and iOS code can call into flutter code. – Shark Nov 12 '20 at 18:02
  • try taking a look at these things: [link1](https://stackoverflow.com/questions/54088421/sending-android-sms-broadcastreceiver-data-to-flutter-through-eventchannel), [link2](https://stackoverflow.com/questions/64052156/how-do-you-use-receiver-broadcastreceiver-in-a-flutter-plugin), [link3](https://stackoverflow.com/questions/54474802/how-to-use-setmethodcallhandler?noredirect=1&lq=1), [link4](https://stackoverflow.com/questions/50187680/how-to-call-methods-in-dart-portion-of-the-app-from-the-native-platform-using-m) – Shark Nov 12 '20 at 18:04

0 Answers0