I'm working on a find phone feature on my company's BLE smartwatch.
The user accesses the option on a smartwatch and it sends a Bluetooth event informing that the user accessed the "find phone" option.
I use a foreground service to send and receive information from the watch.
According to the android documentation, it is not allowed to display a activity from a foreground.
https://developer.android.com/guide/components/activities/background-starts
However, the Samsung Watch has exactly the same function, and they display a screen, even with the apps closed.
How do they do this?
Is it possible to do the same in my app?
This can be achieved by the following steps
Add permission
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
in the AndroidManifest.xml file.
From app settings allow "Appear on Top" to allow your app to draw over other apps.
Add flags Intent.FLAG_ACTIVITY_NEW_TASK, Intent.FLAG_ACTIVITY_SINGLE_TOP to Intent when launching the activity from service like this on the event
val intent = Intent(applicationContext, MainActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)
startActivity(intent)
to launch the activity (in my case it is MainActivity)
NB: