- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
最近我的一个支持 Wear OS (Android Wear) 的应用程序出现了一个错误,当可穿戴设备向它发送数据时,移动设备上的服务永远不会使用react。
在排查根本原因时,我注意到从未调用 WearableListenerService 的 onCreate() 方法。同样,从未调用 Service 父类(super class)的 onStartCommand() 方法,我认为这意味着该 Service 确实没有运行。
Service 定义在 AndroidManifest.xml 中,所以我不明白为什么它不再运行了。
下面是一个新项目的一些代码 fragment ,我所做的就是定义一个 WearableListenerService 并尝试启动它。请注意,这是为了定义在移动设备上运行的服务:
WearMessageListenerService.java
package com.example.test.wearlistenertest;
import android.content.Intent;
import android.util.Log;
import com.google.android.gms.wearable.WearableListenerService;
public class WearMessageListenerService extends WearableListenerService {
@Override
public void onCreate() {
super.onCreate();
Log.v("test", "onCreate()");
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.v("test", "onStartCommand()");
return super.onStartCommand(intent, flags, startId);
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.test.wearlistenertest">
<application
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name="com.example.test.wearlistenertest.WearMessageListenerService">
<intent-filter>
<action android:name="com.google.android.gms.wearable.MESSAGE_LISTENER" />
<data android:scheme="wear" android:host="*" />
</intent-filter>
</service>
</application>
</manifest>
build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.example.test.wearlistenertest"
minSdkVersion 16
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
compile 'com.google.android.gms:play-services-wearable:11.8.0'
}
上面的 Log.v() 方法都没有在运行时输出任何内容。我已经在 API 23 和 27 上进行了测试。
我非常感谢对此提供一些帮助,因为我不明白为什么我无法启动基本服务。我很乐意提供任何其他详细信息。非常感谢您提供的任何帮助。 - 亚伦
最佳答案
在我看来,您对消息接收者的 list 声明是错误的。这是在我的一个应用程序中运行的:
<service android:name=".MyMessageListener"
android:exported="true">
<intent-filter>
<action android:name="com.google.android.gms.wearable.MESSAGE_RECEIVED" />
<data android:host="*" android:scheme="wear"
android:pathPrefix="@string/wear_path_prefix"/>
</intent-filter>
</service>
具体来说,请注意action
应该以MESSAGE_RECEIVED
结尾(您的 list 有MESSAGE_LISTENER
)。我认为这是关键问题,但导出服务并添加 pathPrefix
可能也是个好主意。
关于android - WearableListenerService onCreate() 从未调用过,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50844792/
我正在通过我的手持设备从我的 Wear 向服务发送消息。我第一次单击手持设备上的按钮只是调用服务的 onCreate 方法,第二次服务也收到消息。我无法找出问题所在。 这是我的穿戴部分: @O
我已经实现了 WearableListenerService在我的主应用程序和配套的 Wear 应用程序中。在 list 中,该服务需要声明为 android:exported="true"(或者根本
我正在开发一个带有配套移动应用程序的新穿戴应用程序。 很少需要通过蓝牙连接将信息从手机传输到 watch 。 主要的穿戴应用程序是独立的,因此从手机传输数据是一种奢侈,因为它会比在 watch 上更方
最近我的一个支持 Wear OS (Android Wear) 的应用程序出现了一个错误,当可穿戴设备向它发送数据时,移动设备上的服务永远不会使用react。 在排查根本原因时,我注意到从未调用 We
我创建了简单的 PhoneWear 应用程序。 Wear 应用有一个带有代码的 Activity: public class MainActivity extends Activity impleme
我正在开发一个支持 Android Wear 的 Android 应用。 主应用程序将数据发送到 Android 穿戴应用程序 WearableListenerService,然后发出通知并显示。 我
我正在尝试使用 Wearable.MessageApi 从我的 Android Wear 应用向我的手机应用发送一条简单消息。 这是我在 Wear 设备上来自 GoogleApiClient 的 on
我正在使用 Eclipse IDE 开发 Android Wear 应用程序。我对 Wear 应用程序和移动应用程序使用相同的包名称,并且我正在根据 google documentation 手动打包
我按照教程从手机调用可穿戴 Activity ,发布在这里 How to send notification from handheld to wear to open Activity on wea
有没有办法从 wearableListenerService 调用 Activity 的非静态方法?(绑定(bind)服务对于 wearableListenerService 是不可能的。因为方法 o
我知道这个问题已被多次回答,但作为 Android 的新手,我仍然无法理解给出的答案。例如在这个问题中:How to use an Android Handler to update a TextVi
当我读到 Activity 和 Service 之间的通信时,我发现我们可以使用其中之一 IBinder 信使 AIDL 我对前两个感兴趣。因此,当我尝试实现此功能以在 Activity 和 Wear
我正在使用 Service extends WearableListenerService 开发 android wear 项目。当我尝试添加服务绑定(bind)器时,我看到了这个错误 private
我是一名java/android初学者,正在尝试开发一个简单的穿戴应用程序。 我正在使用 WearableListenerService 来监听来自手机的数据更改并将这些数据显示在可穿戴设备上。这
我有一个 Android 应用程序(除其他外)在 Android Wear 设备上显示通知。 这是通过在 Wear 模块中扩展 WearableListenerService 的类来完成的。在 Wea
我正在尝试使用 Wearable 消息 API 在我的手机和可穿戴设备之间发送消息。手机(实体一加一)和智能 watch (实体索尼智能 watch 3)将相互连接。发送消息也会报告已发送。但是移
我正在开发一款适用于 Android Wear 的应用程序,它可以在手机上启动一项 Activity 。一切都很好,但我不想依赖手机上不断运行的后台服务来接收这条消息。理想情况下,我会让 Wearab
Hello? I am developing android wear app.你好我正在开发安卓穿戴应用程序。 I know that there is a limitation of ba
我是一名优秀的程序员,十分优秀!