gpt4 book ai didi

android - GoogleApiClient onConnected 从未在可穿戴设备上调用

转载 作者:IT王子 更新时间:2023-10-29 00:00:31 24 4
gpt4 key购买 nike

我有一个可穿戴设备,我正在尝试连接到 GoogleApiClient,但从未调用回调(onConnected、onConnectionSuspended 或 onConnectionFailed)。其他一切工作正常,DataLayerListenerService 能够从手持设备接收消息,并且在连接时调用 onPeerConnected。我在模拟器和三星 Gear Live 设备上都试过了。这是我在尝试连接到 GoogleApiClient 的 Activity 中的代码。

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");
}
...
}

不确定是否有帮助,但这是我的可穿戴应用 list

    <?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>

有什么想法吗?

编辑:在可穿戴 list 中添加了以下内容,但仍然无法正常工作

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

最佳答案

哇哦,答案简单得令人尴尬。我错过了在 onStart() 中需要调用 mGoogleApiClient.connect() 的部分。

关于android - GoogleApiClient onConnected 从未在可穿戴设备上调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24681722/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com