Android Wear - 从手持 Action 开始穿戴 Activity

标签 android android-notifications wear-os

我正在从 Android 手持设备向 Android 穿戴设备发送通知。我想在通知中包含一个 Action ,以在 Android 穿戴设备上启动一个 Activity 。

如何将挂起的 Intent 设置为可穿戴设备上的 Activity ?如果通知是在可穿戴设备上创建的,我可以启动 Activity ,但如果通知是在手机上创建然后发送到可穿戴设备,我就不能启动该 Activity 。

 // creating action for push notification created on handheld
 public NotificationCompat.Action CreateWearAppAction(Integer metricId) {
    // I wasnt able to look up the wear's main activity class since this is in the handheld project.
    Intent wearPageIntent = new Intent(Intent.ACTION_VIEW);
    Uri wearUri = Uri.parse("mywearapp://Test?MetricId=" + metricId);
    wearPageIntent.setData(wearUri);
    PendingIntent wearPagePendingIntent = PendingIntent.getActivity(context, 0, wearPageIntent, 0);

    return new NotificationCompat.Action.Builder(R.drawable.ic_action_metric,
            "Open Charts on Wear", wearPagePendingIntent)
            .build();
}

我尝试启动的 Wear 应用的 Activity list :

    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:noHistory="true"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

        <!-- deep link -->
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="mywearapp" />
        </intent-filter>
    </activity>

最佳答案

查看 API 20 的 Android SDK 管理器中包含的 DataLayer 示例。它包含一个示例,说明如何在用户按下移动设备上的按钮后在可穿戴设备上启动 Activity 。

关于Android Wear - 从手持 Action 开始穿戴 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25167859/

相关文章:

android - GCM 更新 7.5 到 8.3.0 致命异常

wear-os - 以编程方式确定Android Wear中的屏幕形状

java - 如何使用 "long"颜色?

java - 创建用于使用 maven 构建的 Apklib

java - 在屏幕上生成通知

java - 服务中的套接字 + 通知

android - 使用一部智能手机/平板电脑连接多个智能 watch

android - 如何运行 Android Sample Watch Face?

android - AsyncTask.doInBackground - Android Scala 项目中抽象方法未实现错误

android - 我可以使用字符串资源在 Jetpack Navigation XML 文件中生成深层链接吗?