有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何从smartwatch启动活动或服务

我曾尝试使用wearablelistener服务,但它们似乎已被弃用

这是我目前的代码:

public void lockdevice(View view) {
  Intent intent = new Intent();
  intent.setClass(this, MainActivity.class);
  intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  RemoteIntent.startRemoteActivity(this, intent,null);
}

它会创建一个异常:

Only 安卓.intent.action.VIEW action is currently supported for starting a remote activity

但是一个视图操作对我没有多大帮助。还有其他方法吗


共 (2) 个答案

  1. # 1 楼答案

    我是通过以下方式实现的。在你的掌上电脑AndroidManifest.xml

    <intent-filter>
        <data android:scheme="appname" android:host="openfromwear" />
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.BROWSABLE" />
    </intent-filter>
    

    在你的Wear应用程序中:

    val intentAndroid = Intent(Intent.ACTION_VIEW)
      .addCategory(Intent.CATEGORY_BROWSABLE)
      .setData(Uri.parse("appname://openfromwear"))
    RemoteIntent.startRemoteActivity(context, intentAndroid, null)