1

I have set up expo notification wherein my app listens to incoming notifications and can execute tasks in the background but my question is how do I bring the app to the foreground upon receiving a notification without the user pressing on the notification first?

Something like this:

import * as Notifications from "expo-notifications";
import * as TaskManager from "expo-task-manager";

const BACKGROUND_NOTIFICATION_TASK = "BACKGROUND-NOTIFICATION-TASK";

TaskManager.defineTask(
  BACKGROUND_NOTIFICATION_TASK,
  ({ data, error, executionInfo }) => {
    console.log("Received a notification in the background!");
    // Bring the app to the foreground
  }
);

Notifications.registerTaskAsync(BACKGROUND_NOTIFICATION_TASK);
  • Are you aware of any apps that do this? I would think this is not supported, and if it is, it probably wouldn't be permitted in the app stores. It would give the developer power to basically hijack your device. – Abe Jul 06 '22 at 00:11
  • Yes, think more like an ordinary phone call or a simple Alarm, they both bring the app to the foreground programmatically – Proff Mushiana Mulweli Jul 06 '22 at 06:58
  • Have you found any solutions? I've been trying expo-linking but it doesn't work from background tasks – ovalb Oct 28 '22 at 10:20
  • No, I haven't. It seems like it is not possible to do this with expo – Proff Mushiana Mulweli Nov 08 '22 at 10:27

1 Answers1

0

The closest thing that you can do, is to create a local notification and encourage the user to press the notification to put the app to the foreground. But the exact thing you are asking is not possible with Android or either with iOS.

Ville Venäläinen
  • 2,444
  • 1
  • 15
  • 11