【问题标题】:Listen to Physical button press from background on Wear OS在 Wear OS 上从后台收听物理按钮按下
【发布时间】:2021-06-25 11:21:58
【问题描述】:

是否可以从 Wear 设备上运行的后台应用监听按钮按下? 我想为 Android 应用创建一个快捷方式,以便当用户按下手表上的物理按钮时,该应用会在配对设备上打开。

谢谢你, 唐尼

【问题讨论】:

    标签: android wear-os


    【解决方案1】:

    添加到清单接收者

        <receiver
            android:name=".services.utils.SearchLongPressReceiver"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.SOS_LONG_PRESS" />
            </intent-filter>
        </receiver>
    

    创建广播接收器

    class SearchLongPressReceiver : BroadcastReceiver() {
        
       override fun onReceive(context: Context, intent: Intent) {
           context.startActivity(Intent(context, SosActivity::class.java))
       }
    }
    

    【讨论】:

    • 是否有关于 SOS_LONG_PRESS 或 SosActivity 的文档?
    • 不,您不会找到此操作的文档。
    猜你喜欢
    • 1970-01-01
    • 2017-03-03
    • 2015-10-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-26
    相关资源
    最近更新 更多