GoogleApiClient onConnected从来没有所谓的可穿戴设备 [英] GoogleApiClient onConnected never called on Wearable device

查看:270
本文介绍了GoogleApiClient onConnected从来没有所谓的可穿戴设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我试图连接到GoogleApiClient可穿戴设备,但回调从来不被称为(onConnected,onConnectionSuspended或onConnectionFailed)。其他一切工作正常,则DataLayerListenerService能够从手持设备接收消息,当它连接onPeerConnected被调用。我同时在仿真器和一台三星齿轮现场设备尝试研究。这是code,我在哪里,我试图连接到GoogleApiClient活动。

 公共类WearReaderActivity扩展活动实现GoogleApiClient.ConnectionCallbacks,GoogleApiClient.OnConnectionFailedListener {
    公共静态最后弦乐CONTENT_EXTRA =contentExtra;
    私人字符串LOG_TAG = WearReaderActivity.class.getSimpleName();

    @覆盖
    保护无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.reader);
        mGoogleApiClient =新GoogleApiClient.Builder(本)
                .addApi(Wearable.API)
                .addConnectionCallbacks(本)
                .addOnConnectionFailedListener(本)
                。建立();
    }

    私人GoogleApiClient mGoogleApiClient;

    @覆盖
    保护无效的OnStart(){
        super.onStart();
        Log.e(连接?,将String.valueOf(mGoogleApiClient.isConnected()));
        //新主题(新的getContent())启动()。
    }

    @覆盖
    公共无效onConnected(束捆){
        Log.d(保持通话,保持通话);
        新主题(新的getContent())启动()。
    }

    @覆盖
    公共无效onConnectionSuspended(int i)以{
        Log.d(连接suspened,连接中断);
    }

    @覆盖
    公共无效onConnectionFailed(ConnectionResult connectionResult){
        Log.d(连接suspened,连接中断);
    }
...
}
 

不知道它会帮助,但,这是我的清单为可穿戴应用

 < XML版本=1.0编码=UTF-8&GT?;
<舱单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
          包=my.packagename>
    <应用
        机器人:allowBackup =真
        机器人:图标=@可绘制/ ic_launcher
        机器人:标签=@字符串/ APP_NAME
        机器人:主题=@安卓风格/ Theme.DeviceDefault>
        &所述;元数据
            机器人:名称=com.google.android.gms.version
            机器人:值=@整数/ google_play_services_version/>

    <活动
        机器人:名称=。WearReaderActivity
        机器人:标签=读与GT;
        <意向滤光器>
           <作用机器人:名称=android.intent.action.MAIN/>
           <类机器人:名称=android.intent.category.LAUNCHER/>
        &所述; /意图滤光器>
    < /活性GT;

<元数据的android:NAME =com.google.android.gms.version
       机器人:值=@整数/ google_play_services_version/>

    <服务
        机器人:名称=DataLayerListenerService。>
        <意向滤光器>
            <作用机器人:名称=com.google.android.gms.wearable.BIND_LISTENER/>
        &所述; /意图滤光器>
    < /服务>

< /用途>
 

任何想法?

编辑:添加下面的耐磨表现,仍然没有工作,虽然

 <元数据的android:NAME =com.google.android.gms.version
           机器人:值=@整数/ google_play_services_version/>
 

解决方案

哇哦,答案是令人尴尬的简单。我错过了在那里的 ONSTART()您需要调用 mGoogleApiClient.connect()部分。

I have a wearable device that I'm trying to connect to the GoogleApiClient but the callbacks are never called (onConnected, onConnectionSuspended or onConnectionFailed). Everything else is working fine, the DataLayerListenerService is able to receive messages from the handheld and the onPeerConnected is being called when it connects. I've tried in on both the emulator and a Samsung Gear Live device. This is the code that I have in the Activity where I'm trying to connect to the GoogleApiClient.

public class WearReaderActivity extends Activity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
    public static final String CONTENT_EXTRA = "contentExtra";
    private String LOG_TAG = WearReaderActivity.class.getSimpleName();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.reader);
        mGoogleApiClient = new GoogleApiClient.Builder(this)
                .addApi(Wearable.API)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .build();
    }

    private GoogleApiClient mGoogleApiClient;

    @Override
    protected void onStart() {
        super.onStart();
        Log.e("Connected?", String.valueOf(mGoogleApiClient.isConnected()));
        //new Thread(new GetContent()).start();
    }

    @Override
    public void onConnected(Bundle bundle) {
        Log.d("Connected", "Connected");
        new Thread(new GetContent()).start();
    }

    @Override
    public void onConnectionSuspended(int i) {
        Log.d("Connection suspened", "Connection suspended");
    }

    @Override
    public void onConnectionFailed(ConnectionResult connectionResult) {
        Log.d("Connection suspened", "Connection suspended");
    }
...
}

Not sure if it'll help but this is my Manifest for the Wearable app

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="my.packagename">
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.DeviceDefault" >
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />

    <activity
        android:name=".WearReaderActivity"
        android:label="Reading" >
        <intent-filter>
           <action android:name="android.intent.action.MAIN" />
           <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

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

    <service
        android:name=".DataLayerListenerService" >
        <intent-filter>
            <action android:name="com.google.android.gms.wearable.BIND_LISTENER" />
        </intent-filter>
    </service>

</application>

Any ideas?

EDIT: Added the following to the wearable manifest, still not working though

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

解决方案

Oh wow, the answer is embarrassingly simple. I missed the part where in onStart() you need to call mGoogleApiClient.connect().

这篇关于GoogleApiClient onConnected从来没有所谓的可穿戴设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆