Hi,
I am trying to use addProximityAlert from LocationManager class, but
it doesn't work. Simply I've two class:
.Test class is the Activity. It has a view with a button. On click of
this button is called the addProximityAlert.
MyBroadcastReceiver class is used to show a Toast message when the
phone is into area set with addProximityAlert.
the problem is that the onReceive of MyBroadcastReceiver is never
fired after that I called addProximityAlert. Follow my snipped code.
thanks, for help.
Permission used:
android.permission.ACCESS_FINE_LOCATION
android.permission.BROADCAST_PACKAGE_REMOVED
android.permission.BROADCAST_STICKY
public class Test extends Activity {
private LocationManager lm;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
lm = (LocationManager)getSystemService
(Context.LOCATION_SERVICE);
Button button = (Button) findViewById(R.id.butAddProximity);
button.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(Test.this,
MyBroadcastReceiver.class);
PendingIntent sender = PendingIntent.getBroadcast
(Yogome.this, 0, intent, 0);
lm.addProximityAlert(
lm.getLastKnownLocation
(LocationManager.GPS_PROVIDER).getLatitude(),
lm.getLastKnownLocation
(LocationManager.GPS_PROVIDER).getLongitude(),
(float)5, -1, sender);
TextView tv = (TextView) findViewById(R.id.TextView01);
String sMsg;
sMsg = "Lat:"+lm.getLastKnownLocation
(LocationManager.GPS_PROVIDER).getLatitude();
sMsg += " Long:"+lm.getLastKnownLocation
(LocationManager.GPS_PROVIDER).getLongitude();
tv.setText(sMsg);
}
});
}
public class MyBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String intentAction = intent.getAction();
String sRx = "Broadcast received:"+intentAction;
Toast.makeText(context, sRx, Toast.LENGTH_SHORT).show();
}
}
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---