当前位置: 首页 > 软件库 > 手机/移动开发 > >

nativescript-wear-messaging

NativeScript Wear Messaging Plugin
授权协议 Apache-2.0 License
开发语言 JavaScript TypeScript
所属分类 手机/移动开发
软件类型 开源软件
地区 不详
投 递 者 闻人冷勋
操作系统 iOS
开源组织
适用人群 未知
 软件概览

NativeScript Wear Messaging Plugin

Adding support for Wear Messaging using the MessageClient API.This plugin is intended to be used to communicate between a handled app and an Android Wear app.

Only Android Supported

Installation

Install the plugin:

tns plugin add nativescript-wear-messaging

Usage

The idea of this plugin is to communicate between a wear device and a handled device. Both can act as receiver or sender, in fact, that's themost common usage way and the one explained here. You need two apps that will communicate to each other, here is described how you can configure this pluginin both:

In the Wear app

Add the following to your AndroidManifest.xml inside your <application> tag. It will create the service listener that will be waitingfor the messages sent by the handled app.

<service android:name="com.berriart.android.nativescriptwearmessaging.MessageListenerService">
    <intent-filter>
        <action android:name="com.google.android.gms.wearable.MESSAGE_RECEIVED" />
        <data android:scheme="wear" android:host="*" />
    </intent-filter>
</service>

Since multiple wearables can be connected to the handheld device, the wearable app needs to determine that a connected nodeis capable of launching the activity. In your wearable app, advertise that the node it runs on provides specific capabilities.We will use this later when sending messages from the handled device.

Create a wear.xml file inside app/App_Resources/Android/values to advertise the capabilities

<resources>
    <string-array name="android_wear_capabilities">
        <item>name_of_your_capabilty_wear</item>
    </string-array>
</resources>

Sending messages to the handled app:

import { WearMessaging } from 'nativescript-wear-messaging';

let client = new WearMessaging();
client.send("/some/path", "some content", "name_of_your_capabilty_handled"); // Last parameter is the capablity name of then handled device

Receiving messages to from the handled app:

import { WearMessaging } from 'nativescript-wear-messaging';

let client = new WearMessaging();
client.registerListener((path: string, content: string) => {
    if (path === "/some/path") {
        console.log(path + " " + content);
    }
});
client.startListener();

*Include the following to your references.d.ts file if you are getting this error: TS2304: Cannot find name 'com'.

/// <reference path="./node_modules/nativescript-wear-messaging/declarations.d.ts" /> Needed for wear-messaging

In the handled app

Add the following to your AndroidManifest.xml inside your <application> tag. It will create the service listener that will be waitingfor the messages sent by the wear app.

<service android:name="com.berriart.android.nativescriptwearmessaging.MessageListenerService">
    <intent-filter>
        <action android:name="com.google.android.gms.wearable.MESSAGE_RECEIVED" />
        <data android:scheme="wear" android:host="*" />
    </intent-filter>
</service>

Since multiple wearables can be connected to the handheld device, the wearable app needs to determine that a connected nodeis capable of launching the activity. In your wearable app, advertise that the node it runs on provides specific capabilities.We will use this later when sending messages from the handled device.

Create a wear.xml file inside app/App_Resources/Android/values to advertise the capabilities

<resources>
    <string-array name="android_wear_capabilities">
        <item>name_of_your_capabilty_handled</item>
    </string-array>
</resources>

Sending messages to the wear app:

import { WearMessaging } from 'nativescript-wear-messaging';

let client = new WearMessaging();
client.send("/some/path", "some content", "name_of_your_capabilty_wear"); // Last parameter is the capablity name of then handled device

Receiving messages to from the wear app:

import { WearMessaging } from 'nativescript-wear-messaging';

let client = new WearMessaging();
client.registerListener((path: string, content: string) => {
    if (path === "/some/path") {
        console.log(path + " " + content);
    }
});
client.startListener();

*You should read the official Android doc anyway.

License

Apache License Version 2.0, January 2018

 相关资料
  • NativeScript Wear OS NativeScript-Wear-OS is a NativeScript plugin that provides layouts and utilities specific to WearOS. Installation NativeScript Version 7+: tns plugin add nativescript-wear-os Nat

  • 我正在开发一个Android Wear应用程序,它从一开始就记录心率,直到用户停止触碰按钮为止,这样我就不会在功能onStop或ondestroy上注销监听器。 问题是当我返回穿戴菜单,再次打开应用程序。在那一刻,应用程序再次注册监听器,并获得所有的测量重复。我尝试在函数onStart和onRestart上注销监听器,但它没有起作用。 下面是我的代码: 提前道谢。

  • NativeScript 可以使用 Javascript,CSS, XML 创建真正的 Native 跨平台应用,支持 iOS Android,NativeScript 将您的跨平台代码翻译成目标平台的代码。 UI 使用 XML 描述,CSS 样式,在编译时将 UI 转化成本地原生代码,最终得到正在的 Native 原生应用。 Telerik 公开了用于创建安卓、iOS和Windows Unive

  • 我正在为三星Gear Live(谷歌I/O版)上的Android Wear开发一个应用程序,它将需要访问心率和步数历史数据。我知道以后可以使用Google Fit SDK访问这些数据,但是现在不使用SDK就可以读取这些数据吗? 我更喜欢访问这个数据而不是根我的G手表。 下面是我要摘录的历史数据截图:

  • 我知道这可能是一个很简单的问题,很多人也问过同样的问题,但我仍然有问题得到心率。我当然为解决方案做了这么多的研究。 这是我的代码,我想要的只是在手表上显示心率。 AwheartRateSensor\Wear\src\main\java\com\example\android\AwheartRateSensor\mainactivity.java 下面是manifest.xml

  • 我正在尝试打包Android wear应用程序,但wear应用程序并没有自动安装在手表中。 我正在使用Eclipse手动打包wear应用程序,如下所述 https://developer.android.com/training/wearables/apps/packaging.html#PackageManually 日志还说安装了磨损应用程序,但我在Watch中找不到该应用程序。这是安装日志,