是DataApi可靠和实战实时?超延迟 [英] Is DataApi Reliable and Practically Real Time? Extremely Delayed

本文介绍了是DataApi可靠和实战实时?超延迟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾在市场上的Andr​​oid Wear应用现在约10个月,它停止工作(不知道当它停止工作)。

I have had an Android Wear app on the market for about 10 months now and it's stopped working (Not sure when it stopped working).

我想更新我的一些统计数据,我在我的手机应用程序记录耐磨应用。正如我所说,这用来做工精细,可靠。我甚至增加了时间戳这所以这是作为 onDataChanged 只调用了独特的数据是否已经改变。这保证了。

I'm trying to update my wearable application with some statistics that I record in my mobile app. As I say, this used to work fine and reliably. I even added the timestamp to this so it was unique as the onDataChanged is only called if data has changed. This guarantees that.

我的问题

我可以通过调用提交 PutDataMa prequest 罚款 Wearable.DataApi.putDataItem 和我得到一个在成功的回调我的 ResultCallback

I can submit the PutDataMapRequest fine by calling Wearable.DataApi.putDataItem and I get a successful callback in my ResultCallback.

onDataChanged 通常被调用最终却迟迟实在太多,超过它曾经是。 Whatsmore,我知道它被设置正确,因为我有我启动,其中我有一个活动的应用程序,我去在 DataItems 并有积压在那里。我有 onDataChanged 在这个活动相同的问题也。

The onDataChanged usually gets called in the end but the delay is just too much and more than it used to be. Whatsmore, I know it's being set correctly because I have an app that I launch, in which I have an Activity that I go and get the DataItems and there is a backlog there. I am having the same issue with onDataChanged in this Activity also.

我做了什么


  1. 确信版本code和跨越的versionName两个模块相匹配的build.gradle 文件。

  2. 有保证的两个的build.gradle 文件使用支持相同版本和Google服务库。

  3. 有保证的两个类都连接到 GoogleApiClient

  4. 确信数据是每次都不同,迫使它叫 onDataChanged 的服务。我不需要这个,但只是为了获得它的工作。

  1. Made sure the versionCode and versionName matches across both module build.gradle files.
  2. Ensured both build.gradle files use the same versions of the support and google services libraries.
  3. Ensured both classes are connecting to GoogleApiClient
  4. Made sure the data is different each time to force it to call onDataChanged in the service. I don't need this but just to get it working.

我的code

移动

if (mGoogleApiClient.isConnected()) {
            PutDataMapRequest putDataMapRequest = PutDataMapRequest.create(path);
            putDataMapRequest.getDataMap().putString("content", content);
            putDataMapRequest.getDataMap().putString("title", title);
            putDataMapRequest.getDataMap().putLong("timestamp", DateTime.now().getMillis());
            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("WearDevice", "buildWatchOnlyNotification(): Failed to set the data, "
                                        + "status: " + dataItemResult.getStatus().getStatusCode());
                            } else {
                                    Log.d(LOG_TAG, "Notificaiton result callback returned successfully: "+dataItemResult.getDataItem().toString());//: "+node.getDisplayName());
                            }
                        }
                    });
}

穿

我有延伸 WearableListenerService 的服务。这是在像这样的清单中声明。

I have a service which extends WearableListenerService. This is declared in the manifest like so.

<service android:name=".NotificationUpdateService">
            <intent-filter>
                <action android:name="com.google.android.gms.wearable.BIND_LISTENER"/>
            </intent-filter>
        </service>

下面是我的服务。

@Override
    public void onCreate() {
        super.onCreate();

        mGoogleApiClient = new GoogleApiClient.Builder(this)
                .addApi(Wearable.API)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .build();

        mGoogleApiClient.connect();
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public void onDataChanged(DataEventBuffer dataEvents) {
        if (MainActivity.DEBUGGING)
            Log.d(LOG_TAG, "onDataChanged");
        for (DataEvent dataEvent : dataEvents) {

            if (dataEvent.getType() == DataEvent.TYPE_CHANGED) {
                DataMap dataMap = DataMapItem.fromDataItem(dataEvent.getDataItem()).getDataMap();
                String content = dataMap.getString("content");
                String title = dataMap.getString("title");
                if ("/mydatapath".equals(dataEvent.getDataItem().getUri().getPath())) {
                    buildWearableOnlyNotification(title, content, false);
                }
            }
        }
    }

buildWearableOnlyNotification 方法创建并启动一个前景通知,并能正常工作时,它实际上调用。

The buildWearableOnlyNotification method creates and starts a foreground notification and this works fine when it's actually called.

推荐答案

您现在需要设置<一个href=\"https://developers.google.com/android/reference/com/google/android/gms/wearable/PutDataMa$p$pquest.html#setUrgent()\"相对=nofollow>如果你希望自己的数据立即同步,急标志否则该框架将批了这些电话,并做他们一个电话,这意味着你可以看到长达30分钟的延迟;这是在最近播放服务作出preserve时,是不是真的需要这样的即时数据同步电池的变化。

You now need to set the urgent flag if you want your data to be synced immediately, otherwise the framework will batch up those calls and do them in one call which means you can see up to 30 minutes delay; it is a change made in the most recent Play Services to preserve the battery when such immediate data sync is not really needed.

这篇关于是DataApi可靠和实战实时?超延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆