在微应用(安卓可穿戴设备)上启动一个活动 [英] Launching an activity on micro app (android wearable)

查看:31
本文介绍了在微应用(安卓可穿戴设备)上启动一个活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过以下方式从我的手机应用程序创建通知.

I am creating notification from my app on Phone in the below way.

   private void launchMicroAppFromWearableNotif() {

   int notificationId = 001;

    // The below action has been defined in the micro app
    Intent i = new Intent("com.microapp.action.PLAY_MUSIC");
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent playPendingIntent =
            PendingIntent.getActivity(this, 0, i, 0);

    NotificationCompat.Builder notificationBuilder =
            new NotificationCompat.Builder(this)
                    .setSmallIcon(R.drawable.play_music)
                    .setContentTitle("Play Music")
                    .setContentText("Play Music on Wear")
                    .setContentIntent(playPendingIntent)
                    .addAction(R.drawable.play_music, getString(R.string.act1), playPendingIntent);

    NotificationManagerCompat notificationManager =
            NotificationManagerCompat.from(this);

    // Build the notification and issues it with notification manager.
    notificationManager.notify(notificationId, notificationBuilder.build());
}

我创建了一个可穿戴微型应用,它有一个 activity(PlayActivity) 和在可穿戴清单中定义的动作 "com.microapp.action.PLAY_MUSIC".

I have created a wearable micro app which has an activity(PlayActivity) with action "com.microapp.action.PLAY_MUSIC" defined in wearable Manifest.

当我从可穿戴设备上的通知中执行操作时,我希望启动来自微应用的活动.但什么也没发生.有人可以帮忙解决这个问题.这样做是否正确?

When I take the action from notification on the wearable I expect the activity form the micro app to be launched. But nothing happens. Could someone please help on this. Is it the right way to do it?

推荐答案

您添加到通知的操作适用于创建通知的设备,因此如果您在手机上创建通知,当您单击它时在您的手表上,操作将被发送回您的手机以执行.

Actions that you add to a notification are for the device that the notification was created on, so if you create a notification on your phone, when you click on it on your watch, the action will be sent back to your phone to be executed.

如果您想在手表上打开您的活动,则无法通过以您的方式从手机发送通知来实现.您有几种选择:例如,您可以从手机向手表发送一条消息,然后让应用程序的穿戴端接收该消息并在手表上发出本地"通知;那么该通知上的操作在您的手表上是本地的,您可以通过该通知中的操作打开您想要的活动.如果你想直接从手机打开手表上的活动(即不需要通知显示在手表上),那么你可以处理我在手表上讲的消息,而不是创建通知在那里,只需打开所需的 Activity.您可能会发现 WearCompanionLibrary 在处理其中一些情况时很有用.

If you want to open your activity on your watch, you cannot achieve that by sending a notification from your phone in the manner you have done. You have a couple of options: for example you can send a message from your phone to your watch and then have the wear side of your app catch that message and put out a "local" notification on the watch; then the actions on that notification are local to your watch and you can open your desired activity via the actions in that notification. If you directly want to open an activity on your watch from your phone (i.e. you don't need a notification to show up on your watch), then you can handle the message that I talked about on your watch and instead of creating a notification there, simply open the desired activity.You may find the WearCompanionLibrary useful in handling some of these cases.

这篇关于在微应用(安卓可穿戴设备)上启动一个活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆