androidsmsnetwork-state

Change network state of phone via sending sms from other phone


i want to change network state of a phone by sending SMS from other phone. is it possible to do so?


Solution

  • You can use SMS received Boardcast receiver. When you received certain kind of sms , You can do your work.

    Add it into your Manifest File
        <receiver
                   android:name =".MyBroadcastReceiver">
                <intent-filter>
                      <action android:name="android.provider.Telephony.SMS_RECEIVED" />
                  </intent-filter>
           </receiver>
    
        //Required permission
    <action android:name="android.provider.Telephony.SMS_RECEIVED" />
    
    import android.content.BroadcastReceiver;
    import android.content.Context;
    import android.content.Intent;
    import android.os.Bundle;
    import android.telephony.SmsMessage;
    import android.util.Log;
    import android.widget.Toast;
    
    //Here is your broadcast receiver class
    public class MyBroadcastReceiver extends BroadcastReceiver{
        private static final String TAG = "MyBroadCastReceiver";
        @Override
        public void onReceive(Context context, Intent intent) {
    
                 Bundle bndl = intent.getExtras();
                SmsMessage[] msg = null;
                String str = "";         
                if (null != bndl)
                {
                    //**** You retrieve the SMS message ****
                    Object[] pdus = (Object[]) bndl.get("pdus");
                    msg = new SmsMessage[pdus.length];         
                    for (int i=0; i<msg.length; i++){
                        msg[i] = SmsMessage.createFromPdu((byte[])pdus[i]);             
                        str += "SMS From " + msg[i].getOriginatingAddress();                   
                        str += " :\r\n";
                        str += msg[i].getMessageBody().toString();
                        str += "\n";
                    }
                    //---display incoming SMS as a Android Toast---
                    System.out.Println(str);
                } 
            }
    }