4

I'm developing a WebRTC app with React Native. I've got Firebase working, and I can receive notifications on my Android/iOS devices whilst in the background or foreground.

Is there any way of when I receive a push-notification to automatically open the app for me, without requiring the user input?

Thanks in advance.

Roham Rafii
  • 2,929
  • 7
  • 35
  • 49

2 Answers2

3

If you are going for the scenario of an incoming call, it's not the same for both platforms. For Android, you can start an activity responding to a push notification, but iOS doesn't allow that. You can either send a regular push notification the user might miss, or use CallKit and integrate it with your stuffs.

Unfortunately I don't know good libraries for React Native that can help you with that yet, so it might have to be done natively and bridged to your RN code.

Edit:

Android example - In your native code handling a notification, you can use context.startActivity(launchIntent); to launch your app with an incoming call screen.

Moti Azu
  • 5,392
  • 1
  • 23
  • 32
  • My goal is to use Callkit for iOS that will allow me to send pushkit notifications that will wake my app from the background , but in Android I dont have that feature so If possible I want to open my app remotely. Can this be done ? – Nicholas Mendes Jun 19 '17 at 09:54
  • Definitely, did it myself for an app. Added some guidance about that. – Moti Azu Jun 19 '17 at 10:26
  • Thanks mate, ill have a look to this. Ill share some feedback as soon as I get something to work. – Nicholas Mendes Jun 19 '17 at 10:34
  • must I write this code on my android files within react native ? – Nicholas Mendes Jun 19 '17 at 13:50
  • You can only do this in Java, maybe you can find some lib to bridge that for you but I don't see a way around it. – Moti Azu Jun 19 '17 at 13:52
  • 1
    It's working mate , I've used this piece of code. `startActivity(launchIntent);` – Nicholas Mendes Jun 19 '17 at 14:38
  • is it possible to startActivity on the background ? and only show the activity when app is fully loaded. – Nicholas Mendes Jun 20 '17 at 09:31
  • At this point I advise you to mark this question solved and open a new one with more details about what you are facing now – Moti Azu Jun 20 '17 at 09:59
  • You need to initiate a new activity while receiving push for incoming call. You can design UI for this screen as per your requirement. Once you receive call from action, you can invoke your react native application from native. – yadav Mar 17 '20 at 20:17
-1

Sorry to deviate a little from the code perspective.

But if you are looking forward for external triggers, I would recommend MacroDroid as a potential solution. There are numerous triggers including Notification reads, SMS etc., Macrodroid is available in Play store with trial version limited to five macros per user. Logical validations, loops and much more features to explore.

vnktrmn
  • 1
  • 2