i want to change network state of a phone by sending SMS from other phone. is it possible to do so?
Asked
Active
Viewed 141 times
-2
-
It is possible. What specific problem are you having? – Mike M. Sep 02 '14 at 05:33
-
i just want to change network state of my device when a specific code as text message is sent to my device from other. – Garjpreet Singh Sep 02 '14 at 08:52
1 Answers
2
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);
}
}
}

Dhruba Bose
- 446
- 2
- 7
-
1Good answer, though you might consider changing where you have `Toast.makeText...` to show an example of changing the network state [like in this answer](http://stackoverflow.com/a/8863540/716588) so that you answer the stated question. – CodeMonkey Sep 02 '14 at 05:57