I'm trying to create the apps in chapter 5 to send and respond to SMSes.
I'm making pretty good progress, but I am never getting to the "onLocationChanged()" event - I've got a breakpoint there, and although the locationListener is created, and requestLocationUpdates() is called, I never even get to the "if (loc != null) {
" line.
Here is my code:
Code:
private BroadcastReceiver intentReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// get sender phone num passed via intent
senderTel = intent.getExtras().getString("senderTel");
// use the LocationManager class to obtain location data
lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
// request location updates
// Change some of these args? First is minimum Time, second is
// minimum Distance
locationListener = new MyLocationListener();
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,
locationListener);
}
};
private class MyLocationListener implements LocationListener {
// @Override - got err msg on this - must override a superclass method
public void onLocationChanged(Location loc) {
if (loc != null) {
// send a SMS containing the current location
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(
senderTel,
null,
"location:" + loc.getLatitude() + ":"
+ loc.getLongitude(), null, null);
// stop listening for location changes
lm.removeUpdates(locationListener);
}
}
I'm sending an SMS from DDMS from 5558 to 5554; it's being received, and parsed correctly, but for some reason MyLocationListener() is not getting fired. Does anybody have an idea why?
BTW, the top of p. 169 says "modify main.xml" where it should actually be the manifest file that's being modified, right?
And p. 168, the super.onPause() should be super.onDestroy(), correct?