Auto location reply by sms
<p>help to develop android app programmatically if receive massage specific number then automatically reply that number to current location latitude and longitude data.</p>

<p>Thank you.</p>

<p>Here this only send location manually, like phone number enter to send sms and use send button.</p>

<p>This replyGps Activity class</p>

<p>package com.pusa.replygps;</p>

<pre><code>import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.TextView;
import android.telephony.SmsManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.view.View;
import android.widget.Toast;
import android.widget.Button;
import android.widget.EditText;


public class Gps extends Activity {

    Button sendButton;
    EditText phoneTexField;

    private TextView mytext;
    private LocationManager locmgr = null;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_gps);

        mytext = (TextView) findViewById(R.id.mytext);

        //grab the location manager service
        locmgr = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

        mytext.setText("waiting for location");

        //make btn
        sendButton = (Button) findViewById(R.id.sendButton);
        //phone number
        phoneTexField = (EditText) findViewById(R.id.phoneTextField);
    }

    //Start a location listener
    LocationListener onLocationChange=new LocationListener() {
        public void onLocationChanged(Location loc) {
            //sets and displays the lat/long when a location is provided
            String latlong = loc.getLatitude()  +  ","   + loc.getLongitude();   
            mytext.setText(latlong);
        }

        public void onProviderDisabled(String provider) {
        // required for interface, not used
        }

        public void onProviderEnabled(String provider) {
        // required for interface, not used
        }

        public void onStatusChanged(String provider, int status,
        Bundle extras) {
        // required for interface, not used
        }
    };

    //pauses listener while app is inactive
    @Override
    public void onPause() {
        super.onPause();
        locmgr.removeUpdates(onLocationChange);
    }

    //reactivates listener when app is resumed
    @Override
    public void onResume() {
        super.onResume();
        locmgr.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,10000.0f,onLocationChange);
    }

       public void send(View v)
       {
           String phoneNumber = phoneTexField.getText().toString();
           String msg = mytext.getText().toString();

           if (phoneNumber.length()&gt;0 &amp;&amp; msg.length()&gt;0)
           {
               PendingIntent pi = PendingIntent.getActivity(this, 0, new Intent(this, Gps.class), 0);
               SmsManager sms = SmsManager.getDefault();
               sms.sendTextMessage(phoneNumber, null, msg, pi, null);

           }
           else
           {
               Toast.makeText(getBaseContext(), "OK",Toast.LENGTH_SHORT).show();
           }

       }
}
</code></pre>

<p>and This ReplyGps Manifest.xml</p>

<pre><code>&lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/&gt;
&lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/&gt;
&lt;uses-permission android:name="android.permission.SEND_SMS"/&gt;
</code></pre>

<p>How to reply automatically when sms receive.</p>

<p>Thank you,</p>
