1

I want to make an aaplication that has the feature of controlling my phone from remotely.Such as on/off GPS through text message from another phone.Getting the location from phone via text message.

Is it possible to on/off gps through text message from another phone?

  • The answers you are getting are correct as far as SMS goes. However, depending on which version of Android the "receiving" phone is running, it may or may not be possible to toggle the GPS state. I believe that since ICS, it is not. Prior versions had a flaw that could be exploited to do so. Check these: http://stackoverflow.com/questions/10302894/ics-android-enable-gps-programmatically and http://stackoverflow.com/questions/15426144/turning-on-and-off-gps-programmatically-in-android-4-0-and-above – Mike M. Mar 17 '14 at 09:53

2 Answers2

1

Definitely yes.

You just need to add in you application a receiver for the Action android.provider.Telephony.SMS_RECEIVED and parse the message text if you recognize ac command in your phone, you execute some code.

Basically you need to do three things:

  1. Update you manifest abd add permission for your application to receive SMS:

    <uses-permission android:name="android.permission.RECEIVE_SMS"/>
    
  2. Then you have to add, again in the manifest a receiver, that receive the SMS_RECEIVED Action, in a way similar to the following:

    <receiver android:name=".SMSReceiver" android:enabled="true" >
            <intent-filter>
                <action android:name="android.provider.Telephony.SMS_RECEIVED" />
            </intent-filter>
    

Where android.name is the name of your Receiver class.

  1. And finally you have to implement that class, that extends BroadCastReceiver and has at least the onReceive Method implemented.

    public class SmsReceiver extends BroadcastReceiver {     
    
       public void onReceive(Context context, Intent intent) {
       }
    }
    

For your help, below there an example onReceive code:

@Override
    public void onReceive(Context context, Intent intent) {
        Bundle bundle = intent.getExtras();
        Object[] pdus = (Object[])bundle.get("pdus");
        SmsMessage[] messages = new SmsMessage[pdus.length];
        for(int i = 0; i &lt; pdus.length; i++){
            messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
        }
        for(SmsMessage message: messages){
            String messagestr = message.getMessageBody();
            String sender = message.getOriginatingAddress();
            Toast.makeText(context, sender + ": " + messagestr, Toast.LENGTH_SHORT).show();
        }
    }

That code, read the message content and show it on a Toast. You can find a full working example here: https://github.com/inuyasha82/ItalialinuxExample/tree/master/LezioniAndroid

prakash
  • 1,413
  • 1
  • 21
  • 33
Ivan
  • 4,186
  • 5
  • 39
  • 72
  • If you give me the full code or a understandable resource it will be useful for me as I am novice to droid. –  Mar 17 '14 at 09:51
  • You can find some examples on my github account, at that link: https://github.com/inuyasha82/ItalialinuxExample/tree/master/LezioniAndroid (consider giving +1 or accept it if you like that answer) – Ivan Mar 17 '14 at 10:02
  • Your github code show that how to send and receive sms but I want to know how to turn gps on/off through sms.give me a full descriptive article if you have as soon as possble. –  Mar 17 '14 at 11:13
0

Recieving (handling) SMS-es is possible with Android. Your software should read the SMS, then decide if it contains command and turn off the GPS like normal app would.

This link shows how http://www.apriorit.com/dev-blog/227-handle-sms-on-android

Senad Uka
  • 1,131
  • 7
  • 18