donny.rewq
donny.rewq

Reputation: 641

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

Upvotes: 2

Views: 280

Answers (1)

J-iSkELo
J-iSkELo

Reputation: 103

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))
   }
}

Upvotes: -1

Related Questions