NativeScript Version 7+:
tns plugin add nativescript-wear-os
NativeScript version prior to 7:
tns plugin add nativescript-wear-os@2.1.1
WAKE_LOCK
permission to your AndroidManifest.xml<uses-permission android:name="android.permission.WAKE_LOCK" />
Copy the ambient-activity.ts
in the root of this project's demo app and use it to replace the default Android Activity loaded by NativeScript. NativeScript docs HERE about using a custom Android Activity.
Update the AndroidManifest.xml for your application to use the correct activity. Change the android:name
value of the activity
node to point to the same name used inside the ambient-activity.ts
file inside the @JavaProxy()
decorator at the top of the file.
<activity android:name="com.nativescript.AmbientActivity" android:label="@string/title_activity_kimera" android:configChanges="keyboardHidden|orientation|screenSize" android:theme="@style/LaunchScreenTheme">
// Add your custom Activities, Services and other Android app components here.
const appComponents = [
'@nativescript/core/ui/frame',
'@nativescript/core/ui/frame/activity',
resolve(__dirname, 'app/ambient-activity'),
];
A base layout for Wear OS apps built with NativeScript that automatically handles calculating the inset for circle watch faces. To disable the layout from automatically adjusting the inset set disableInsetConstraint="true"
on the WearOsLayout
instance. The default is false and does not have to be set.
This has no effect on square watches.
<Page xmlns="http://schemas.nativescript.org/tns.xsd" actionBarHidden="true"
xmlns:ui="nativescript-wear-os/packages/wear-os-layout">
<ui:WearOsLayout disableInsetConstraint="false">
<ScrollView height="100%">
<StackLayout>
<Label text="Going to put a long string of text so we can fill the screen with other view components to show how this works on Circle and Square watch faces." class="c-white" textWrap="true" />
<GridLayout rows="auto, auto, auto" columns="*, *, *">
<Button text="Go Back" tap="navBack" class="yellowBtn" row="0" col="0" />
<Image src="res://icon" stretch="aspectFit" row="0" col="1" />
<Button text="Wow" class="greenBtn" row="0" col="2" />
<Button text="Fantastic" row="1" col="0" />
<Label text="Something something something" class="c-white" row="1" col="1" textWrap="true" />
<Label text="Something Text" row="1" col="2" />
<Button text="Yay" row="2" col="0" />
<Image src="res://icon" stretch="aspectFit" row="2" col="1" />
<Button text="Okay" row="2" col="2" />
</GridLayout>
</StackLayout>
</ScrollView>
</ui:WearOsLayout>
</Page>
Circle Watch | Square Watch |
---|---|
<Page xmlns="http://schemas.nativescript.org/tns.xsd"
xmlns:wear="nativescript-wear-os/packages/listview">
<StackLayout>
<wear:WearOsListView useScalingScroll="true" height="100%" items="{{ items }}">
<wear:WearOsListView.itemTemplate>
<GridLayout rows="*" columns="auto, *">
<Image src="{{ image }}" row="0" col="0" />
<Label text="{{ title }}" row="0" col="1" />
</GridLayout>
</wear:WearOsListView.itemTemplate>
</wear:WearOsListView>
</StackLayout>
</Page>
useScalingScroll - If true, the items in the listview will scale during the scroll layout change event.
<Page xmlns="http://schemas.nativescript.org/tns.xsd" loaded="pageLoaded" actionBarHidden="true"
xmlns:ui="nativescript-wear-os/packages/box-inset-layout">
<ui:BoxInsetLayout>
<StackLayout height="100%" width="100%">
<Label text="This is a box inset layout. It's purpose is for short views so you don't have to calculate the inset for your layout manually. So don't try using a ScrollView with it." class="text-white" textWrap="true"/>
<GridLayout rows="50" columns="*, *">
<Button col="0" text="Go Back" class="greyBtn" tap="navBack" />
<Button col="1" text="Okay" class="yellowBtn" />
</GridLayout>
</StackLayout>
</ui:BoxInsetLayout>
</Page>
This plugin uses an Android WearOS specific library SmartWearOs.
The plugin has a success dialog and failure/error dialog to present on WearOS. These mimic the behavior of the built in Confirmation Activity on WearOS. With the option of setting the time before it is dismissed/hidden from the user.
import {
showFailure,
showSuccess,
} from 'nativescript-wear-os/packages/dialogs';
showSuccess('Great choice! NativeScript is awesome.', 4).then(() => {
console.log('success dialog complete.');
});
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 A
我正在开发一个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中找不到该应用程序。这是安装日志,