I created simple Phone<->Wear App.
Wear app has one Activity with code:
public class MainActivity extends Activity implements GoogleApiClient.ConnectionCallbacks {
private TextView mTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final WatchViewStub stub = (WatchViewStub) findViewById(R.id.watch_view_stub);
stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() {
@Override
public void onLayoutInflated(WatchViewStub stub) {
mTextView = (TextView) stub.findViewById(R.id.text);
}
});
getGoogleApiClient(this).connect();
}
private GoogleApiClient getGoogleApiClient(Context context) {
return new GoogleApiClient.Builder(context)
.addApi(Wearable.API)
.addConnectionCallbacks(this)
.build();
}
@Override
public void onConnected(Bundle bundle) {
Toast.makeText(this, "onConnected", Toast.LENGTH_SHORT).show();
}
@Override
public void onConnectionSuspended(int i) {
Toast.makeText(this, "onConnectionSuspended", Toast.LENGTH_SHORT).show();
}}
And Phone app has one WearableListenerService
public class ListenerOfConnection extends WearableListenerService {
private static final String TAG = "DataLayerListenerServic";
protected GoogleApiClient googleApiClient;
@Override
public void onCreate() {
super.onCreate();
Toast.makeText(ListenerOfConnection.this, "onCreate", Toast.LENGTH_SHORT).show();
googleApiClient = new GoogleApiClient.Builder(this)
.addApi(Wearable.API)
.build();
googleApiClient.connect();
}
@Override
public void onPeerConnected(Node peer) {
super.onPeerConnected(peer);
Toast.makeText(ListenerOfConnection.this, "onPeerConnected", Toast.LENGTH_SHORT).show();
LOGD(TAG, "onPeerConnected: " + peer);
}
@Override
public void onPeerDisconnected(Node peer) {
super.onPeerDisconnected(peer);
Toast.makeText(ListenerOfConnection.this, "onPeerDisconnected", Toast.LENGTH_SHORT).show();
LOGD(TAG, "onPeerDisconnected: " + peer);
}
public static void LOGD(final String tag, String message) {
if (Log.isLoggable(tag, Log.DEBUG)) {
Log.d(tag, message);
}
}}
The problem is that onPeerConnected
and onPeerDisconnected
are never called, also onCreate
is not called if I not send any message.
And if i send few messages onCreate
is called but onPeerConnected
and onPeerDisconnected
never...
Before questions to me:
1. applicationId is the same
2. onConnected
is called on wearable Activity