Does Wearable.DataApi.getDataItems users UriMatcher

362 views Asked by At

I'm trying to extract all data from Wearable.DataApi that matches wear:/someAttr/*

The motivation is that I'm using PutDataRequest.createWithAutoAppendedId since I want to avoid overriding data written in the wearable device.

I would like to match the following URI:

wear:/someAttr/3/rand1
wear:/someAttr/2/rand2
wear:/someAttr/3/rand6

But avoid

wear:/someOtherAttr/3/rand1

Can I use wildcard to get data from DataAPI?

I have a current workaround of not providing a URI to Wearable.DataApi.getDataItems which brings all the data but includes unwanted DataItems that I would wish to avoid.

Any ideas?

1

There are 1 answers

0
Ika On

I found the solution in a similar question by @dzeikei

From Android official documentation

int FILTER_PREFIX Filter type for getDataItems(GoogleApiClient, Uri, int), deleteDataItems(GoogleApiClient, Uri, int): if this filter is set, the given URI will be taken as a path prefix, and the operation will apply to all matching items.

So in order to match my example you would use

Uri.Builder builder = new Uri.Builder();
builder.scheme(PutDataRequest.WEAR_URI_SCHEME).path("someAttr");
Uri uri = builder.build();
PendingResult<DataItemBuffer> pendingResult = Wearable.DataApi.getDataItems(googleApiClient, uri, DataApi.FILTER_PREFIX);