私はエミュレータと時計を同期しようとしています。正しく手順を踏んで、携帯電話を時計に接続しました。これまでのところ私は携帯電話から時計の顔を変更し、いくつかの通知を処理することができます。私は自分のアプリの時計の顔を作成して、私は時計に温度を表示していません。時計エミュレータとAndroid Phoneの間でデータが同期されていません
private void connectToWatchFace() {
Log.d(LOG_TAG, "connectToWatchFace()");
mGoogleApiClient = new GoogleApiClient.Builder(getContext())
.addApi(Wearable.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
mGoogleApiClient.connect();
}
private void sendDataToWatchFace(double highTemperature, double lowTemperature, int weatherConditionId) {
Log.d(LOG_TAG, "sendDataToWatchFace()");
PutDataMapRequest putDataMapRequest = PutDataMapRequest.create("/sunshine").setUrgent();
putDataMapRequest.getDataMap().putDouble("high_temperature", highTemperature);
putDataMapRequest.getDataMap().putDouble("low_temperature", lowTemperature);
putDataMapRequest.getDataMap().putLong("timestamp", new Date().getTime());
Log.d(LOG_TAG, "High Temperature: " + highTemperature + " " + "Low Temperature: " + lowTemperature);
int drawableResourceId = Utility.getIconResourceForWeatherCondition(weatherConditionId);
Bitmap bitmap = BitmapFactory.decodeResource(getContext().getResources(), drawableResourceId);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 80, byteArrayOutputStream);
Asset asset = Asset.createFromBytes(byteArrayOutputStream.toByteArray());
putDataMapRequest.getDataMap().putAsset("icon", asset);
PutDataRequest putDataRequest = putDataMapRequest.asPutDataRequest();
Wearable.DataApi.putDataItem(mGoogleApiClient, putDataRequest)
.setResultCallback(new ResultCallback<DataApi.DataItemResult>() {
@Override
public void onResult(@NonNull DataApi.DataItemResult dataItemResult) {
if (dataItemResult.getStatus().isSuccess()) {
Log.d(LOG_TAG, "dataItemResult.getStatus().isSuccess()");
} else {
Log.d(LOG_TAG, "NOT dataItemResult.getStatus().isSuccess()");
}
}
});
}
これは私が携帯電話からのデータを受信していているコードです:
は、ここで私は時計と私のデータを同期しています中のために私のコードです。
@Override
public void onDataChanged(DataEventBuffer dataEventBuffer) {
Log.d(TAG, "onDataChanged()");
for (DataEvent dataEvent : dataEventBuffer) {
DataItem dataItem = dataEvent.getDataItem();
String path = dataItem.getUri().getPath();
Log.d(TAG, "path: " + path);
if (path.equals("/sunshine")) {
DataMap dataMap = DataMapItem.fromDataItem(dataItem).getDataMap();
mHighTemperature = dataMap.getDouble("high_temperature");
mLowTemperature = dataMap.getDouble("low_temperature");
Log.d(TAG, "high temperature: " + mHighTemperature + ", low temperature: " + mLowTemperature);
Asset iconAsset = dataMap.getAsset("icon");
if (iconAsset != null) {
new SunshineWatch.Engine.LoadBitmapAsyncTask().execute(iconAsset);
}
// Force UI update
invalidate();
}
}
}
private class LoadBitmapAsyncTask extends AsyncTask<Asset, Void, Bitmap> {
@Override
protected Bitmap doInBackground(Asset... params) {
if (params.length > 0 && params[0] != null) {
Asset asset = params[0];
InputStream assetInputStream = Wearable.DataApi.getFdForAsset(
mGoogleApiClient, asset).await().getInputStream();
if (assetInputStream == null) {
Log.w(TAG, "Requested an unknown Asset.");
return null;
}
return BitmapFactory.decodeStream(assetInputStream);
} else {
Log.e(TAG, "Asset must be non-null");
return null;
}
}
@Override
protected void onPostExecute(Bitmap bitmap) {
if (bitmap != null) {
Log.d(TAG, "onPostExecute bitmap is NOT null");
mIconBitmap = Bitmap.createScaledBitmap(
bitmap,
getResources().getDimensionPixelSize(R.dimen.icon_width_height),
getResources().getDimensionPixelSize(R.dimen.icon_width_height),
false
);
invalidate();
} else {
Log.d(TAG, "onPostExecute bitmap is NULL");
}
}
}
}
LOGCATでも結果は見つかりません。私はプレイサービスバージョン10.0.0を使用しています
最新のGoogle Playサービス10.0.0 – Contextioner
W/GooglePlayServicesUtil:Google Playのサービスが古くなっています。 10084000が必要ですが、見つかった9841574 12-12 13:17:20.030 2750-2750/com.sagar。sunshine D/SunshineWatch:onConnectionFailedConnectionResult {statusCode = SERVICE_VERSION_UPDATE_REQUIRED、resolution = null、message = null} – Contextioner