标签: android-wear-2.0

无法连接到 Android 可穿戴健康服务

我尝试使用以下指南阅读 Android Wear(三星 Galaxy Watch 4)的步行步骤:https://developer.android.com/training/wearables/health-services/active

这是我的代码的一部分:

val healthClient = HealthServices.getClient(this /*context*/)
        val measureClient = healthClient.measureClient
        lifecycleScope.launch {
            val capabilities = measureClient.capabilities.await()
            supportsStepCount =
                DataType.WALKING_STEPS  in capabilities.supportedDataTypesMeasure
        }
Run Code Online (Sandbox Code Playgroud)

但我收到这个异常:

Connection to service is not available for package 'com.google.android.wearable.healthservices' and action 'com.google.android.wearable.healthservices.MeasureClient'.
2021-09-07 11:04:18.112 4523-6821/com.daftar.galaxyface E/ServiceConnection: Connection disconnected and maximum number of retries reached.
    java.util.concurrent.CancellationException: Service not available
        at androidx.health.services.client.impl.ipc.internal.ServiceConnection.connect(ServiceConnection.java:145)
        at androidx.health.services.client.impl.ipc.internal.ServiceConnection.enqueue(ServiceConnection.java:203)
        at androidx.health.services.client.impl.ipc.internal.ConnectionManager.handleMessage(ConnectionManager.java:123)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:246)
        at android.os.HandlerThread.run(HandlerThread.java:67)
Run Code Online (Sandbox Code Playgroud)

注意:上面的指南中有一个注释是获取权限,但没有提到哪些权限。我尝试了 ACTIVITY_RECOGNITION 和 BODY_SENSORS 和 ACCESS_FINE_LOCATION,但没有成功。

watch-face-api watchface android-wear-2.0 wearables samsung-galaxy-watch

5
推荐指数
1
解决办法
1031
查看次数

如何在 Android Wear 中的 ScrollView 中添加旋转输入

我正在开发一个 Android Wear 应用程序,我已经使用 rcView.requestFocus() 将旋转输入添加到 recyclerview,但它不适用于 NestedScrollview,所以我想知道如何将旋转输入侦听器添加到 NestedScrollview。

这是我到目前为止所做的

   binding.mainScroll.setOnGenericMotionListener { v, ev ->
            if (ev.action == MotionEvent.ACTION_SCROLL &&
                ev.isFromSource(InputDeviceCompat.SOURCE_ROTARY_ENCODER)
            ) {

                val delta = -ev.getAxisValue(MotionEventCompat.AXIS_SCROLL) *
                        ViewConfigurationCompat.getScaledVerticalScrollFactor(
                            ViewConfiguration.get(applicationContext), applicationContext
                        )
                
                v.scrollBy(0, delta.roundToInt())
                true
            } else {
                false
            }
        }
Run Code Online (Sandbox Code Playgroud)

android android-wear-2.0 wear-os android-wear-3.0

5
推荐指数
1
解决办法
1090
查看次数

如何从Android磨损并发症提供商在表盘上绘制图标?

使用Complications API有一个图标类型,但是在绘制图标时我不知道该怎么做.

当我绘制实际的表盘时,似乎没有drawIcon方法.例如像canvas.drawIcon(icon).我只能看到如何绘制位图.

在我的drawComplications方法中我有这个:

} else if (complicationData.getType() == ComplicationData.TYPE_ICON) {
                Icon icon = complicationData.getIcon();
Run Code Online (Sandbox Code Playgroud)

然后我如何将图标绘制到画布?

这里的代码实验室没有告诉我们如何绘制图标:https://codelabs.developers.google.com/codelabs/complications/index.html?index =..% 2F..%2Findex#3

我可以只将所有drawable复制到本地可穿戴模块,并通过传入一个字符串绕过图标​​类型,然后从那里绘制相应的位图.但必须有一种方法可以从图标中提取,否则为什么会这样呢?

我也无法从谷歌搜索中找到如何将图标转换为位图,但这似乎也很愚蠢,因为我不得不首先将位图转换为图标,因为API需要一个图标.

任何帮助赞赏.

谢谢.

android android-wear-data-api android-wear-2.0 android-wear-complication wear-os

4
推荐指数
1
解决办法
511
查看次数

Android Wear 2.0支持watch face app

我有一个Android手表应用程序,同时具有移动和磨损模块.

我想让这个应用程序准备好进行2.0更新,我已经访问了Android开发人员建议的所有网站,我了解几乎所有即将发生变化的内容,但后来变为现实,我坚持了第一个简单的步骤.

在这里读到:

如果您构建一个独立的Wear 2.0 APK并将继续使用Wear 1.0 APK,请执行以下两项操作:

提供Wear APK的独立版本,并继续在手机APK中嵌入Wear APK版本

然后我们在这里:

如果您的应用同时支持Wear 1.x和Wear 2.0,请继续在手机APK中嵌入Wear 1.x APK(最低SDK版本20,21或22或23)并上传手机APK.此外,上传您的独立Wear 2.0 APK(其最低SDK版本为24).

因此,我想继续支持Android 1.x,我该怎么做?

如何在模块中设置SDK版本号?

我是否需要复制带有更改的SDK版本的磨损模块来构建单独的可穿戴apk?

黄金和王国适用于已成功完成任务的任何人,并将提供使应用程序兼容当前和即将推出的Wear版本的所有必要步骤.

sdk android android-wear-2.0

4
推荐指数
1
解决办法
1369
查看次数

从 Android Wear 获取心率

我知道这可能是一个非常简单的问题,很多人都问过同样的问题,但我在获取心率方面仍然遇到问题。当然,我已经为解决方案做了很多研究。

一般来说,要使用心率传感器,我们需要获得权限使用sensormanager,并且需要在mainActivity中为传感器注册监听器。

这里有人说对于SDK 23或更高版本,我们需要单独声明权限,但到目前为止我只开发了Android Wear的部分,没有关于手机的部分。

我还尝试重新安装并重新运行该应用程序。所有这些方法对我都不起作用。

这是我的代码,我想要的只是在手表上显示心率。

AWHeartRateSensor\wear\src\main\java\com\example\android\awheartratesensor\MainActivity.java

package com.example.android.awheartratesensor;

import android.app.Activity;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.support.wearable.view.WatchViewStub;
import android.util.Log;
import android.widget.TextView;

import static com.google.android.gms.wearable.DataMap.TAG;

public class MainActivity extends Activity {

private SensorManager mSensorManager;
private Sensor mHeartSensor;
private TextView mTextView;
WatchViewStub mStub;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
        mStub = (WatchViewStub) findViewById(R.id.watch_view_stub);
    mStub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() {
        @Override
        public void onLayoutInflated(WatchViewStub stub) {
            mTextView = (TextView) stub.findViewById(R.id.text);
            mTextView.setText("I am …
Run Code Online (Sandbox Code Playgroud)

android android-wear-2.0 wear-os

4
推荐指数
1
解决办法
7481
查看次数

访问android Wear数据层时出错

我试图访问数据可穿戴层作为显示与手机应用交流这里

但是,在编写以下行之后:

DataClient dataClient = Wearable.getDataClient(context);

Android lint 在 Android Studio 中标记它并显示以下错误:

Cannot access com.google.android.gms.hasApiKey

任何人都可以帮助我了解此错误的含义以及如何解决它。

PS:我已经通过向我的 gradle 文件添加必要的配置来集成 Google Play Services API。

android android-wear-data-api android-wear-2.0 wear-os

4
推荐指数
1
解决办法
252
查看次数

使用编译'com.google.android.support:wearable:2.0.4'时,我收到以下错误,但我没有使用26.0.0

在我的Wear应用程序的build.gradle文件中使用compile 'com.google.android.support:wearable:2.0.4'(最新版本com.google.android.support:wearable)时,我收到以下错误,但我没有使用26.0.0.

我该怎么办?即使我添加了编译'com.android.support:wear:26.0.0',它仍然会失败.

Error in the project's gradle file: 

Error:(22, 13) Failed to resolve: com.android.support:wear:26.0.0
<a href="install.m2.repo">Install Repository and sync project</a><br><a href="openFile:/.../wear/build.gradle">Show in File</a><br><a href="open.dependency.in.project.structure">Show in Project Structure dialog</a>
Run Code Online (Sandbox Code Playgroud)

android android-support-library android-wear-2.0 wear-os

2
推荐指数
1
解决办法
2865
查看次数

ScalingLazyColumn (Jetpack Compose Wear OS) 默认行为中的错误

我使用ScalingLazyColumn ,里面有很长的文本,如下所示:

@Preview(device = Devices.WEAR_OS_SMALL_ROUND, showSystemUi = true)
@Composable
fun Test(modifier: Modifier = Modifier) {
    val scalingLazyState = remember { ScalingLazyListState() }
    val focusRequester = remember { FocusRequester() }

    Scaffold(
        modifier = modifier,
        positionIndicator = { PositionIndicator(scalingLazyListState = scalingLazyState) }
    ) {
        ScalingLazyColumn(
            modifier = Modifier.scrollableColumn(focusRequester, scalingLazyState),
            state = scalingLazyState,
        ) {
            item {
                Text(
                    longText,
                    Modifier
                        .padding(top = 20.dp, start = 16.dp, end = 16.dp, bottom = 48.dp),
                    textAlign = TextAlign.Center,
                )
            }
        }

    }
} …
Run Code Online (Sandbox Code Playgroud)

android-wear-2.0 wear-os android-jetpack android-jetpack-compose android-jetpack-compose-material3

2
推荐指数
1
解决办法
934
查看次数