Android Wear watches



since android wear devicesare worn by the users, they're the ideal platform toimplement fitness applications. these types of applicationstypically use sensors on the device to measure step counts,acceleration, and position. the good news is that android wearuses exactly the same sensor api


Android Wear watches, as regular android phones andtablets, so you can use all your existingknowledge about sensors here as well. let's look at a sampleto see how it works. a good one is called jumping jack.


so let's create a projectaround that and test it. in this case, i'm going to usea real watch to test it out and show you how it works. right now, it has zero onthe counter shown in the activity. so let's do a few jumping jacks. one, two, three and now, you can seethat it's counted the values correctly. so what is different about workingwith sensors on android wear? well, the main differences comedown to saving battery power, and not doing too much processingon the wearable device.


let's go through some best practices forsensors on android wear. you want to do as littlework as possible. so unregister your listenerwhen you don't need it. for a running app, we only want to log steps when the useris running the actual activity. for the rest of the day when theactivity is not running, we should put the device to sleep and usethe standard watch face saving power. the next things is to selectan appropriate update rate. if you're going to refreshthe display every minute,


then there's no point gettingupdates ten times per second. and you might also want to requestthat the results are batched up over this time period, so that the cpucan stay asleep the whole time. the registerlistener method allowsyou to control these factors. also, make sure if youneed to process the data, try to do as much onthe phone as possible. remember, the phone has a huge batterycompared to the little wearable here. so take advantage of that. if you're trying to measurethe bumpiness of a car ride, and


you know the wearable user hastheir phone with them, why not use the accelerometer on the phone to dothe logging instead of the wearable? the gps feature in android weardoes exactly this. if you have the phone and the wearable in close proximity, itwill actually use the phone's gps unit. if the wearable goes out on a runwhile the phone stays at home and if the device has a gps built in,it'll use the gps from the wearable. there's a sample forthis called speed tracker. check it out for yourself andsee how it's implemented.


when you sensor that wasintroduced in kitkat phones and available on all wearablesis the step counter. this is really useful forfitness applications and is a low power sensor you can use often. it's also a lot more efficient thantrying to build your own step counter by reading the accelerometers. the android step counter isprovided by dedicated hardware. you'll notice in the documentationthere is a type_step_detector, and a type_step_counter.


the detector is configured to triggerevery time a step is made, but it's possible that you'll not receivethe events if the device is sleeping. you also don't want to havethe device wake up and run your code after every single step,like at these points here. especially if you only refreshthe display every minute. so the step counter hereis a much better idea.


Android Wear watches

it gives you an absolute value, so your code does not needto wake up on every step. and you cannot miss any steps,


because you always getthe absolute value each time.


Android Wear watches Rating: 4.5 Diposkan Oleh: PaduWaras