简体   繁体   English

通过Data API从移动设备发送的数据无法在Android Wear中接收?

[英]Data sent through Data API from mobile not received in android wear?

Data sent through Data API from mobile app is not received in ondatachange of listenerservice in wearable emulator.I can send a notification though, which indicates both are connected.Below my code, 可穿戴式模拟器中的监听器服务的ondatachange不会接收通过数据API从移动应用发送的数据。尽管如此,我仍可以发送通知,表明两者均已连接。在我的代码下方,

DataAPI call (mobile) DataAPI调用(移动)

   PutDataMapRequest putDataMapRequest = PutDataMapRequest.create(SharedConstants.START_FREE_RUN);
   putDataMapRequest.getDataMap().putString(SharedConstants.PROGRAM_TYPE,totalCountUpTimer);

    PutDataRequest request = putDataMapRequest.asPutDataRequest();
    Wearable.DataApi.putDataItem(mGoogleApiClient, request)
            .setResultCallback(new ResultCallback<DataApi.DataItemResult>() {
                @Override
                public void onResult(DataApi.DataItemResult dataItemResult) {
                    if (!dataItemResult.getStatus().isSuccess()) {
                        Log.e(TAG, "buildWatchOnlyNotification(): Failed to set the data, "
                                + "status: " + dataItemResult.getStatus().getStatusCode());
                    } else {
                        Log.d(TAG,"SuccessFully sent notification");
                    }
                }
            });

After which I am getting "successfully sent" log message. 之后,我会收到“成功发送”日志消息。

Below is ListenerService in wear, 下面是ListenerService的外观,

  public class ListenerService extends WearableListenerService {

  private static final String TAG =   ListenerService.class.getSimpleName();
  @Override
  public void onDataChanged(DataEventBuffer dataEvents) {
     super.onDataChanged(dataEvents);
     Log.d(TAG, "dchanged" + dataEvents);

  }
  @Override
  public void onMessageReceived(MessageEvent messageEvent) {
     Log.v(TAG, "onMessageReceivedWear: " + messageEvent);

     if  (SharedConstants.START_FREE_RUN.equals(messageEvent.getPath())) {
        // Request for this device open the attraction detail screen
        // to a specific tourist attraction
        String Distance = new String(messageEvent.getData());
        Log.d("ListenerService",Distance);

     }
 }
 }

and my service declaration in Android manifest, 以及我在Android清单中的服务声明,

    <service android:name=".services.ListenerService">
        <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="*" android:pathPrefix="*" />
       </intent-filter>
    </service>
  <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

Did not add any permissions in wearable module.Do suggest. 未在可穿戴模块中添加任何权限。建议。

使用android:pathPattern=".*"代替android:pathPrefix="*"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM