我正在从 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/