Hello group,
I read several posts and other resources but I don't find the answer
or a solution for my problem.
I try to program the addProximityAlert() API to get notified if the
current position is near an area of interrest. But it seems that no
alert willl be fired. According to this issue (http://code.google.com/
p/android/issues/detail?id=107) the problem should not be relevant
with my configuration.
If a send the broadcast manually, the implemented BroadcastReceiver
works as expected.
Has anybody a working example how to use the addProximityAlert() API?
Or is the problem within my example implementation?
Here is the code:
-------------------------------------------------------------------------------------------------------------------------------------
package com.example.proximitytest;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
public class ProximityTest extends Activity {
private static final String TAG = "ProximityTest";
private final String POI_REACHED =
"com.example.proximitytest.POI_REACHED";
private PendingIntent proximityIntent;
private final double sampleLatitude = 52.0522193;
private final double sampleLongitude = 9.8942044;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setupProximityAlert();
}
private void setupProximityAlert() {
LocationManager locationManager = (LocationManager)
getSystemService(LOCATION_SERVICE);
if
(locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
Log.d(TAG, "Registering ProximityAlert");
Intent intent = new Intent(POI_REACHED);
proximityIntent =
PendingIntent.getBroadcast(getApplicationContext(), 0, intent,
PendingIntent.FLAG_ONE_SHOT);
locationManager.addProximityAlert(sampleLatitude,
sampleLongitude, 50, 1000000,
proximityIntent);
IntentFilter intentFilter = new
IntentFilter(POI_REACHED);
registerReceiver(new ProximityAlertReceiver(),
intentFilter);
} else {
Log.d(TAG, "GPS_PROVIDER not available");
}
}
private class ProximityAlertReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent) {
Log.d(TAG, "Proximity Alert was fired");
}
}
}
-------------------------------------------------------------------------------------------------------------------------------------
I also set the follwing permissions:
android.permission.ACCESS_MOCK_LOCATION
android.permission.ACCESS_COARSE_LOCATION
android.permission.ACCESS_FINE_LOCATION
android.permission.ACCESS_WIFI_STATE
I would be very grateful for a hint to solve my problem.
Thanks
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en