'4003: Data item to large sending data from wear os to app
I'm developing a wear os app that needs to send a list of "MyObject" to mobile,
data class MyObject(
val id: String,
val name: String,
val locations: List<MyLatLong>,
...
)
data class MyLatLong(
val id: String,
val lat: Double,
val long: Double
)
When I try to send a myObject with 100 or 200 myLatLong objects there is no problem, but when I have 1000 myLatLong objects, I received a 4003 DATA_ITEM_TO_LARGE exception message
I use DataClient to send the DataMapItem with this function:
fun sendMyObjectRequest(myObject: MyObject) {
val dataClient = Wearable.getDataClient(appContext)
val request = PutDataMapRequest.create("/my_object_path").apply {
dataMap.putDataMap("key_my_object", myObject.toDataMap())
}.asPutDataRequest().setUrgent()
dataClient.putDataItem(request).addOnFailureListener {
//Exception received
}
}
//Extension to map MyObject into DataMapa
fun MyObject.toDataMap(): DataMap = DataMap().apply {
putString("id", id)
....
putDataMapArrayList("locations", ArrayList(locations.map { it.toDataMap() })
}
fun MyLatLong.toDataMap(): DataMap = DataMap().apply {
putString("id", id)
putDouble(...)
....
}
How can I send this objects from wear to mobile?
Solution 1:[1]
The first location disappear because you're overwrite it, you are creating new data item with same path. Try to use createWithAutoAppendedId instead of create method on PutDataMapRequest. If error persists then convert data item to Asset of bytes from your map object. There is a limit size, see the doc.
PutDataMapRequest
.createWithAutoAppendedId(YOUR_PATH);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | jereghi |
