我刚刚开始向现有的eclipse项目添加磨损支持。到目前为止,我已完成以下步骤:
1)添加一个使用布局的新活动:
<?xml version="1.0" encoding="utf-8"?>
<android.support.wearable.view.WatchViewStub xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/yt.ty"
android:id="@+id/watch_view_stub"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:rectLayout="@layout/activityrect"
app:roundLayout="@layout/activityround" >
</android.support.wearable.view.WatchViewStub>
activityrect.xml和activityround xml文件是:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World_RectangeScreen" />
</LinearLayout>
在我的活动中,我现在仅显示Toast消息。我的问题是,这种磨损活动将如何在磨损下运行。我已经有了一个意图为“ android.intent.action.MAIN”的MainActivity,可以在手机和平板电脑上运行。
您必须在Eclipse中设置磨损项目。就像这里描述的一样http://blog.benjamin-cabe.com/2014/07/04/how-to-setup-eclipse-for-android-wear-development老实说,在Android Studio中开发起来会容易得多,但还是由您决定。
如果您想在穿戴设备上看到自己穿戴的应用,则需要打包穿戴项目(或使用释放键构建包含磨损的手机)。然后,您可以通过IDE或adb来安装your.package.wear进行安装
如果已经完成了前面的步骤,并且想从移动应用程序中打开穿戴应用程序,那么您需要发送消息以穿戴设备
移动部分:
私人无效sendStartActivityMessage(String node){
Wearable.MessageApi.sendMessage( mGoogleApiClient, node, START_ACTIVITY_PATH, new byte[0]).setResultCallback( new ResultCallback<SendMessageResult>() { @Override public void onResult(SendMessageResult sendMessageResult) { if (!sendMessageResult.getStatus().isSuccess()) { Log.e(TAG, "Failed to send message with status code: " + sendMessageResult.getStatus().getStatusCode()); } } } ); }
磨损部位:
公共无效onMessageReceived(MessageEvent messageEvent){
if (messageEvent.getPath().equals(START_ACTIVITY_PATH)) { Intent startIntent = new Intent(this, MainActivityWear.class); startIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(startIntent); } }
在磨损示例项目中检查https://developer.android.com/training/wearables/data-layer/messages.html和DalaLayer项目。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句