meine App funktioniert gut, bis BIND_LISTENER veraltet und ich habe jede Änderung vorgenommen, aber meine App funktioniert nicht. Ich sende die Daten erfolgreich ab, aber auf der Telefonseite passiert nichts.Nicht in der Lage, Daten zu empfangen, nachdem BIND_LISTENER veraltet
Mein Hauptcode auf den Verschleiß (der 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();
}
}
Mein Verschleiß 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>
Der Zuhörer Service auf der Telefonseite:
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);
}
}
}
}
Mein Telefon 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>
Danke, ich habe das versucht und es hat nicht geholfen – Timmy
Sie haben gerade gesehen, dass Sie vergessen haben, den Pfad zum Manifest des Telefons hinzuzufügen. Die obige Bearbeitung könnte helfen. –
Hallo Eric, danke für den Kommentar, das hat für mich keinen Unterschied gemacht. Wie auch immer, ich änderte diese Art und Weise, dass ich die Daten sendete und begann von Grund auf neu [https://gist.github.com/gabrielemariotti/117b05aad4db251f7534] und es funktioniert jetzt gut – Timmy