ウェアラブル上に、ボタンクリックでハンドヘルドにデータマップを送信する必要があるアプリがあります。私はハンドヘルドから電話までほぼ同じ設定をしましたが、唯一の違いは私が完全に動作するメッセージを送ったことです。今はDataMap
を別の方法で送ろうとしています。WearableListenerServiceのonDataChangedが電話で呼び出されていない
電話機のwearableListenerService
にあるonDataChanged()
の電話番号は決して正しく設定されていません。私は何か重要なことを忘れてしまったのでしょうか?
私の一日を見て保存してください! :)
ウェアラブルからデータマップを送信するスレッドがあります(ウェアラブルのmainActivityから呼び出され、googleClientが存在し、スレッドを開始しました)。デバッグは、データマップが正常に送信されたことを返します。
public class SendDataMapToHandheldDataLayer_Thread extends Thread {
private String path;
private DataMap dataMap;
private GoogleApiClient googleClient;
public SendDataMapToHandheldDataLayer_Thread(String cPath, DataMap cDataMap, GoogleApiClient cGoogleClient){
path = cPath;
dataMap = cDataMap;
googleClient = cGoogleClient;
}
public void run(){
PutDataMapRequest putDMR = PutDataMapRequest.create(path);
putDMR.getDataMap().putAll(dataMap);
PutDataRequest request = putDMR.asPutDataRequest();
DataApi.DataItemResult result = Wearable.DataApi.putDataItem(googleClient, request).await();
if(result.getStatus().isSuccess()){
Log.v("dataMapSender_Wear", "DataMap successfully sent!");
}else{
Log.v("dataMapSender_Wear", "ERROR: Failed to send DataMap to data layer");
}
}
}
ここでは、決して呼び出されない電話のリスナーがあります。どうして?基本的には、ここにあるアンドロイド開発者チュートリアルのコピー:http://developer.android.com/training/wearables/data-layer/events.html#Listenです。自分のバージョンも試しましたが、問題はどこかにあると思います。
public class ListenerServiceMobile extends WearableListenerService{
private static final String TAG = "DataLayerSample";
private static final String START_ACTIVITY_PATH = "/start-activity";
private static final String DATA_ITEM_RECEIVED_PATH = "/data-item-received";
@Override
public void onDataChanged(DataEventBuffer dataEvents) {
Toast.makeText(getApplicationContext(), "Data changed!", Toast.LENGTH_LONG).show();
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG, "onDataChanged: " + dataEvents);
}
final List<DataEvent> events = FreezableUtils
.freezeIterable(dataEvents);
GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this)
.addApi(Wearable.API)
.build();
ConnectionResult connectionResult =
googleApiClient.blockingConnect(30, TimeUnit.SECONDS);
if (!connectionResult.isSuccess()) {
Log.e(TAG, "Failed to connect to GoogleApiClient.");
return;
}
// Loop through the events and send a message
// to the node that created the data item.
for (DataEvent event : events) {
Uri uri = event.getDataItem().getUri();
// Get the node id from the host value of the URI
String nodeId = uri.getHost();
// Set the data of the message to be the bytes of the URI
byte[] payload = uri.toString().getBytes();
// Send the RPC
Wearable.MessageApi.sendMessage(googleApiClient, nodeId,
DATA_ITEM_RECEIVED_PATH, payload);
}
}
モバイルのマニフェストファイルには、これを含んでいます
<service android:name=".ListenerServiceMobile">
<intent-filter>
<action android:name="com.google.android.gms.wearable.DATA_CHANGED"></action>
<data android:scheme="wear" android:host="*" android:pathPrefix="/prefix" />
</intent-filter>
</service>
答えていただきありがとうございます! :)