Android Wear 兼容

开发环境:手表端使用Android Studio,手机端使用Eclipse

目标:兼容中国版,国际版,Ticwear

备注:Ticwear是基于Android定制的手表系统

手表端兼容步骤:

1)    将google-play-services-7-8-87文件夹加入到工程中,Mobvoi-api.jar加入到app文件夹下的libs目录下。

2)    将工程模块下的build.gradle添加加入的包,以及对Ticwear的依赖。

buildscript {

    repositories {

        jcenter()

    }

    dependencies {

        classpath 'com.android.tools.build:gradle:1.5.0'

        classpath 'com.ticwear.tools.build:gradle:1.1.0'

}

allprojects {

    repositories {

        jcenter()

        maven {

            url "${rootProject.projectDir}/google-play-services-7-8-87"

        }

    }

}

3)    在app模块的build.gradle中com.android.application下添加ticwear插件,在模块依赖中添加wearable:7.8.87。

apply plugin: 'com.ticwear.application'

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.google.android.support:wearable:1.3.0'
    compile 'com.google.android.gms:play-services-wearable:7.8.87'
}

4)将程序中用到google包中的类全部换成Mobvoi包中对应的类。
5) 在APP启动的时候需要调用MobvoiApiManager.getInstance().adaptService(context), 该方法必须在任何可能的API调用操作前调用(建议在Application.onCreate中调用),它将会自动探测当前系统情况,选择底层是使用MMS或GMS。
   在Application中的onCreate中添加如下程序

if (!MobvoiApiManager.getInstance().isInitialized()) {

    try {

        MobvoiApiManager.getInstance().adaptService(this);

    } catch (NoAvailableServiceException e) {

        Log.e(TAG, "no avaliable service.", e);

        return;

    }

}
6) 修改配置文件
          A)   将WearableListenerService的监听action由com.google.android.gms.wearable.BIND_LISTENER 改为com.mobvoi.android.wearable.BIND_LISTENER
          添加GMS Wearable Listener Service的代理服务:

<service android:name=

      "com.mobvoi.android.wearable.WearableListenerServiceGoogleImpl">

         <intent-filter>

                    <action android:name=

                "com.google.android.gms.wearable.BIND_LISTENER" />

        </intent-filter>

</service>
B)添加键值对
<meta-data
   
android:name="com.google.android.gms.version"
   
android:value="@integer/google_play_services_version" />
<meta-data
   
android:name="com.google.android.wearable.version"
   
android:value="@integer/google_play_services_version" />
这两个不添加的话,通信不成功
 
<meta-data
   
android:name="com.google.android.wearable.local_edition_compatible"
   
android:value="true" />
          这个在手表端可以不添加,因为Ticwear插件可以在编译的时候会添加上这个参数,但是手机端没有Ticwear插件,就必须添加这个键值对,否则会导致Wear应用无法同步到手表。安装的时候会报Failed to add com.XXXXX.plat.android错误。
     C)包名,版本号,版本名改成和手机端一致。

7)对于Ticwear,要求MobvoiApiClient对象所处线程有消息循环,需要在线程中添加Looper.prepare()和Looper.loop(),否则会报can’t create handler inside thread that has has not called Looper.prepared()错误。

8)采用和手机端一样的keystore对apk签名。

 

手机端兼容步骤:

1、从play-services-base-7.8.87.aar和play-services-wearable-7.8.87文件中取出class.jar,命名和aar文件一样(防止混淆),和mobvoi-api.jar文件放在lib文件夹下,将aar资源文件中version.xml取出加入到工程的资源文件xml目录下。

2、将程序中所有的google包中的类换成Mobvoi中的,假如用不同包的DataMap传输会报Datamap:deserialize dataMap failed  错误。(有一个地方用到了DataMap,却不在com.wearable包中)

3、在XXXXXApplication的onCreate中添加选择底层是使用MMS或GMS的程序。

4、修改混淆文件obfuscatedApp_linux ,防止刚加入的jar包被混淆。

5、配置文件中WearableListenerService 中IntentFilter不能使用<data>标签设置Uri,否则会报如下警告,导致无法收到消息。

WearableListenerService: discard a onMessageReceived event, no mobvoi listener is ready.

用demo测试,发送DataItem的时候,Uri是这样的wear://24b1cf24//function/data,但是只要添加了<data>标签,不管是什么样子的都报上面的警告使得通信不能进行。

添加如下配置

<meta-data
                    
android:name="com.google.android.wearable.local_edition_compatible"
                       
android:value="true" />

<meta-data
   
android:name="com.google.android.gms.version"
   
android:value="@integer/google_play_services_version" />
<meta-data
   
android:name="com.google.android.wearable.version"
   
android:value="@integer/google_play_services_version" />

 

6、wearable_app_desc文件中wearableApp标签的 package属性必须和应用包名一样,下面的versionCode,versionName也要设置成和应用的一样。

注意:

1)测试国际版时,不能同时安装Android Wear中国版助手和TicWear助手。假如安装了中国版助手,则手机不能向手表发数据;安装了Ticwear助手,不能正常通信。假如先安装了中国版,再卸载会使国际版在前几次通信中出现问题,多试几次才行。

2)测试中国版时,不能安装Ticwear助手。安装Android Wear国际版无影响。

3)测试Ticwear时,安装国际版和中国版都无影响,但是最好是单独安装Ticwear助手测试。

4)刷机的时候,需要先重启长按电源键进入fastboot,再用USB连接电脑,这个顺序不能反,否则长按电源键只会开机和进入setting界面。

posted @ 2016-03-23 12:47  Maydow  阅读(895)  评论(0编辑  收藏  举报