'Listen to Physical button press from background on Wear OS
Is it possible to listen for a button press from a background app running on a Wear device? I would like to create a shortcut for an Android app so that when the user presses a physical button on a watch, the app opens on a paired device.
Thank you, Donny
Solution 1:[1]
add to manifest receiver
<receiver
android:name=".services.utils.SearchLongPressReceiver"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.SOS_LONG_PRESS" />
</intent-filter>
</receiver>
create BroadcastReceiver
class SearchLongPressReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
context.startActivity(Intent(context, SosActivity::class.java))
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | J-iSkELo |
