作者热门文章
- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我有一个可穿戴设备,我正在尝试连接到 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/
我是一名优秀的程序员,十分优秀!