使用 Wear 应用程序运行应用程序,无需手表 [英] Run App with Wear app without watch
问题描述
我想制作一个带有可选穿戴应用的应用.
I want to make an app with optional wear app.
如果设备有配对的手表,请在手表上安装应用程序.但如果没有,移动应用程序应该可以正常工作.
If device has a paired watch, so install app on watch. But if not, the app mobile should works withou a wear.
我在 Android Studio 上创建了一个项目并选择创建一个移动和穿戴应用,但是当项目执行时抛出错误:
I created a project on Android Studio and select to create a mobile and wear app, but when the project is executed throw a error:
Caused by: java.lang.IllegalStateException: Could not find wearable shared library classes. Please add <uses-library android:name="com.google.android.wearable" android:required="false" /> to the application manifest
at android.support.wearable.activity.WearableActivity.initAmbientSupport(WearableActivity.java:187)
at android.support.wearable.activity.WearableActivity.onCreate(WearableActivity.java:70)
at com.mundocompilado.sesamo.MainActivity.onCreate(MainActivity.java:25)
at android.app.Activity.performCreate(Activity.java:6259)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1130)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Native Method)
那么,我怎样才能让一个带有 option wear 的应用程序有效?
So, how can I make a app with option wear works?
Obs:我有两个项目:移动和穿戴
Obs: I have two projects: mobile and wear
移动:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mundocompilado.sesamo">
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
磨损:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mundocompilado.sesamo">
<uses-feature android:name="android.hardware.type.watch" android:required="false"/>
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@android:style/Theme.DeviceDefault">
<uses-library
android:name="com.google.android.wearable"
android:required="false" />
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.DeviceDefault.Light">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
有什么帮助吗?
推荐答案
我发现了问题.在android studio中的运行"按钮左侧有一个可选择的模块,默认情况下我的项目被选择为wear.所以我改用移动项目,效果很好.
I found the problem. In left of button "Run" in android studio has a selectable module, by default mine project was selected wear. So I changed to mobile project and works well.
这篇关于使用 Wear 应用程序运行应用程序,无需手表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!