Public onStatusChanged

 

// required for interface, not used

 

 

Here, all we do is call with the supplied to the callback method. The implementation, as shown in Chapter 30, builds a Web page with the current forecast for the location and sends a broadcast so the activity knows an update is available.

When you no longer need the updates, call with the you registered.

 

Are We There Yet? Are We There Yet? Are We There Yet?

 

Sometimes you want to know not where you are now, or even when you move, but when you get to where you’re going. This could be an end destination, or it could be getting to the next step on a set of directions so you can give the user the next turn.

To accomplish this, offers . This registers a , which will be fired off when the device gets within a certain distance of a certain location. The method takes the following as parameters:

• The latitude and longitude of the position that you are interested in.

• A radius, specifying how close you should be to that position for the Intent to be raised.

• A duration for the registration, in milliseconds – after this period, the registration automatically lapses. A value of ‑1 means the registration lasts until you manually remove it via .

• The to be raised when the device is within the “target zone” expressed by the position and radius.

Note that it is not guaranteed that you will actually receive an Intent if there is an interruption in location services or if the device is not in the target zone during the period of time the proximity alert is active. For example, if the position is off by a bit and the radius is a little too tight, the device might only skirt the edge of the target zone, or go by so quickly that the device’s location isn’t sampled while in the target zone.

It is up to you to arrange for an activity or intent receiver to respond to the you register with the proximity alert. What you then do when the arrives is up to you: set up a notification (e.g., vibrate the device), log the information to a content provider, post a message to a Web site, etc. Note that you will receive the whenever the position is sampled and you are within the target zone – not just upon entering the zone. Hence, you will get the several times, perhaps quite a few times depending on the size of the target zone and the speed of the device’s movement.

 

Testing… Testing…

 

The Android emulator does not have the ability to get a fix from GPS, triangulate your position from cell towers, or identify your location by some nearby WiFi signal. So, if you want to simulate a moving device, you will need to have some means of providing mock location data to the emulator.

For whatever reason, this particular area has undergone significant changes as Android itself has evolved. It used to be that you could provide mock location data within your application, which was very handy for demonstration purposes. Alas, those options have all been removed as of Android 1.0.

One likely option for supplying mock location data is the Dalvik Debug Monitor Service (DDMS). This is an external program, separate from the emulator, which can feed the emulator single location points or full routes to traverse, in a few different formats. DDMS is described in greater detail in Chapter 37.

 

 








Дата добавления: 2015-05-16; просмотров: 867;


Поиск по сайту:

При помощи поиска вы сможете найти нужную вам информацию.

Поделитесь с друзьями:

Если вам перенёс пользу информационный материал, или помог в учебе – поделитесь этим сайтом с друзьями и знакомыми.
helpiks.org - Хелпикс.Орг - 2014-2024 год. Материал сайта представляется для ознакомительного и учебного использования. | Поддержка
Генерация страницы за: 0.003 сек.