I want to alert the user when he is near a particular location. For this I have included a ProxmityAlert and a corresponding service in my app. But no matter what coordinates I give, it always shows me "Thank you for visiting my Area!! entering" Am I doing this the wrong way?
This is how I am doing it :
public class ProxTest extends Activity {
LocationManager lm;
double lat = 30.085514, long1 = 77.082603;
float radius = 50;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lm = (LocationManager) getSystemService(LOCATION_SERVICE);
Intent i = new Intent();
i.setAction("com.example.test.proximityalert");
PendingIntent pi = PendingIntent.getBroadcast(getApplicationContext(),
-1, i, 0);
lm.addProximityAlert(lat, long1, radius, -1, pi);
sendBroadcast(i);
System.out.println("Prox alert added ");
}
}
And this is the receiver :
public class ProximityReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context arg0, Intent arg1) {
// TODO Auto-generated method stub
String k = LocationManager.KEY_PROXIMITY_ENTERING;
boolean state = arg1.getBooleanExtra(k, false);
if (state) {
Toast.makeText(arg0, "Welcome to my Area", Toast.LENGTH_LONG)
.show();
} else {
Toast.makeText(arg0, "Thank you for visiting my Area!!"+k,
Toast.LENGTH_LONG).show();
}
}
}
In the Manifest, I have added :
<receiver android:name="ProximityReceiver">
<intent-filter>
<action android:name="com.example.test.proximityalert">
</action>
</intent-filter>
</receiver>