onDataChanged代理怪异

时间:2018-10-11 22:34:09

标签: java android android-studio wear-os

我正在尝试使用我的wearOS应用程序扩展我的Paint应用程序。每当尝试添加新点时,我都尝试将Bitmap发送到Wear应用程序,但这导致了可怕的延迟。

我尝试序列化Path数组,但是随后很快发现我可以通过点和函数传递三个不同的绘制特征(开始,移动,结束)。

这是我的onMove尝试:

public void sendPoint(Point p)
{
    long[] newPoint = new long[2];
    newPoint[0] = p.x;
    newPoint[1] = p.y;
    PutDataMapRequest dataMap = PutDataMapRequest.create("/count");
    dataMap.getDataMap().putLongArray("count", newPoint);
    PutDataRequest request = dataMap.asPutDataRequest();
    Task<DataItem> putTask = Wearable.getDataClient(this).putDataItem(request);
}

在介绍onStart和onEnd之前-我想指出以下确切的代码:

 public void sendPaint(Bitmap b)
    {
        Bitmap bitmap = b;
        Asset asset = createAssetFromBitmap(bitmap);
        PutDataMapRequest dataMap = PutDataMapRequest.create("/image");
        dataMap.getDataMap().putAsset("profileImageX", asset);
        PutDataRequest request = dataMap.asPutDataRequest();
        Task<DataItem> putTask = Wearable.getDataClient(this).putDataItem(request);
    }

我能够发送我的位图。

我之所以说这很奇怪,是因为我所做的只是更改.putAsset

 dataMap.getDataMap().putAsset("profileImageX", asset);

到.putLongArray

  dataMap.getDataMap().putLongArray("count", newPoint);

关于为什么这种方法无效的任何想法?我注意到sendData仅在数据是新数据时才有效,也许这就是问题所在。在这种情况下,我想知道如何在WearOS应用中接收并使用“数据”后将其删除。

1 个答案:

答案 0 :(得分:0)

android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE"

为了在您的gradle中工作也需要

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "your.applicationid" // needs to be the same in both modules
        minSdkVersion 20
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        targetCompatibility = '1.7'
}

...

也正如您所说,我认为您需要一直放置一些真正新颖的东西,例如System MillTimes

dataMap.getDataMap().putLong("Time",System.currentTimeMillis())