my app has been working fine until BIND_LISTENER deprecated and I have done any change needed but my app is not working. I send the data from wear successfully but nothing happen on the phone side.
My main code on the wear (the sender):
public class MainActivity extends Activity implements
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener {
private TextView mTextView;
GoogleApiClient googleClient;
String WEARABLE_DATA_PATH = "/wearable_data";
ArrayList<String> dataBlock = new ArrayList();
Button startButton;
@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);
}
});
startButton = (Button) findViewById(R.id.startButton);
// Build a new GoogleApiClient that includes the Wearable API
googleClient = new GoogleApiClient.Builder(this)
.addApi(Wearable.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
}
@Override
public void onConnected(Bundle connectionHint) {
Log.v("CONNECTED", "CONNECTED");
DataMap map = new DataMap();
map.putLong("Time",System.currentTimeMillis());
new SendToDataLayerThread(WEARABLE_DATA_PATH, map).start();
}
public void onStartClicked(View view) {
Log.v("StartClicked", "in on start clicked");
googleClient.connect();
}
@Override
public void onConnectionSuspended(int cause) {
Log.v("Suspended", "Suspended");
}
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
Log.v("Failed", "onConnectionFailed: ConnectionResult.getErrorCode() = "
+ connectionResult.getErrorCode());
}
class SendToDataLayerThread extends Thread {
String path;
DataMap dataMap;
// Constructor for sending data objects to the data layer
SendToDataLayerThread(String p, DataMap data) {
path = p;
dataMap = data;
}
public void run() {
// Construct a DataRequest and send over the data layer
PutDataMapRequest putDMR = PutDataMapRequest.create(path);
putDMR.getDataMap().putAll(dataMap);
putDMR.setUrgent();
PutDataRequest request = putDMR.asPutDataRequest();
DataApi.DataItemResult result = Wearable.DataApi.putDataItem(googleClient, request).await();
if (result.getStatus().isSuccess()) {
Log.v("myTag", "DataMap: " + dataMap + " sent successfully to data layer ");
}
else {
// Log an error
Log.v("myTag", "ERROR: failed to send DataMap to data layer");
}
}
}
protected void onPause() {
super.onPause();
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
protected void onResume() {
super.onResume();
}
@Override
protected void onStart() {
super.onStart();
}
}
My wear Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myname.datacollector">
<uses-feature android:name="android.hardware.type.watch" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@android:style/Theme.DeviceDefault">
<activity
android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
The listener service on the phone side:
public class ListenerService extends WearableListenerService {
//private static final String START_ACTIVITY_PATH = "/start-activity";
private static final String WEARABLE_DATA_PATH = "/wearable_data";
public void onMessageReceived(MessageEvent messageEvent) {
Log.v("myTag", "Test");
}
public void onDataChanged(DataEventBuffer dataEvents) {
DataMap dataMap;
Log.v("myTag", "DataMap received from watch: ");
for (DataEvent event : dataEvents) {
// Check the data type
if (event.getType() == DataEvent.TYPE_CHANGED) {
// Check the data path
String path = event.getDataItem().getUri().getPath();
if (path.equals(WEARABLE_DATA_PATH)) {}
dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap();
Log.v("myTag", "DataMap received on watch: " + dataMap);
}
}
}
}
My phone manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.name.datacollector">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".ListenerService" android:exported="false">
<intent-filter>
<action android:name="com.google.android.gms.wearable.DATA_CHANGED"/>
<action android:name="com.google.android.gms.wearable.MESSAGE_RECEIVED" />
<data android:scheme="wear"
android:host="*"/>
</intent-filter>
</service>
</application>
</manifest>