I'm developing an app to send user location via SMS
after a fixed time.
I have almost accomplished my task. I'm only facing problem when GPS
location is not get SMS
is sent but when i on GPS
the sending sms is not working.
String myAddress = "";
List<Address> location;
private void getAddress() {
// TODO Auto-generated method stub
try {
startService(new Intent(mContext,GPSTracker.class));
GPSTracker tracker = new GPSTracker(mContext);
location = tracker.getGeocoderAddress(mContext);
if (tracker.canGetLocation() == false)
{
tracker.showSettingsAlert();
}
else
{
GlobalValues.location_home_lat = tracker.getLongitude();
GlobalValues.location_home_lng = tracker.getLatitude();
}
if(location != null) {
Address returnedAddress = location.get(0);
StringBuilder strReturnedAddress = new StringBuilder("location:\t");
for(int i=0; i<returnedAddress.getMaxAddressLineIndex(); i++) {
strReturnedAddress.append(returnedAddress.getAddressLine(i)).append("\n");
}
myAddress = strReturnedAddress.toString();
}
private void countdownStart() {
// TODO Auto-generated method stub
detectionStart.setBase(SystemClock.elapsedRealtime());
detectionStart.start();
detectionStart.setOnChronometerTickListener(new OnChronometerTickListener() {
@Override
public void onChronometerTick(Chronometer chronometer) {
// TODO Auto-generated method stub
long elapsedMillis = SystemClock.elapsedRealtime() - detectionStart.getBase();
Date date = new Date(elapsedMillis);
DateFormat formatter = new SimpleDateFormat("s");
String dateFormatted = formatter.format(date);
detectionStart.setText(dateFormatted);
if(elapsedMillis>THRESHOLD){
if(userNumber.length()>0 && message.length()>0){
sendSms(userNumber,message);
}
else{
Toast.makeText(getBaseContext(),
"Error in sendind sms",
Toast.LENGTH_SHORT).show();
}
stopAlarm();
onCloseActivity();
goMainActivity();
}
}
});
}
protected void sendSms(String number, String message) {
// TODO Auto-generated method stub
String SENT = "android.telephony.SmsManager.STATUS_ON_ICC_SENT";
String DELIVERED = "SMS_DELIVERED";
PendingIntent sentPI = PendingIntent.getBroadcast(DoorbellDetectedActivity.this, 0,
new Intent(SENT), 0);
PendingIntent deliveredPI = PendingIntent.getBroadcast(DoorbellDetectedActivity.this, 0,
new Intent(DELIVERED), 0);
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(userNumber, null, message, null, null);
}
Hope it helps