vij
vij

Reputation: 143

how to wake on remote pc using message service provided by android?

is it possible to create an android application, which runs always in background and keep listening to a message from a particular mobile number and particular format, and take necessary actions? This is an idea i ve got to wake up remote pc(please see previous question). I need to use 2 android phones for this purpose, phone A and phone B. B is in remote place and is connected to wireless network through wifi always. It keeps on listening to a message from A( SMS from A). Now if A sends message like "WAKE ON PC EE:00:B3:2F:56:12 password" to B, then B should parse this message in Background and send magic packet to the pc with paricular mac address. This is just an idea. Is it possible to create this kind of application?

initial setup:

        wired               wired    
modem------------router--------------PC(mac:EE:00:B3:2F:56:12)
                   |
                   |
                   |
                 wireless
                   |
                   |
                   |
                   ------------------android phone(B)  

hi, is it possible to send messages between 2 applications in android(that is in the above problem, instead of A sending message to B's Inbox, is it possible for A to send message to a specific application running in B other than inbox?)?

Upvotes: 0

Views: 576

Answers (1)

113408
113408

Reputation: 3444

For the part of the SMS listner you can use a BroadcastReceiver and read from your Pdus like that:

public class SmsController extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
    this.c=context;
    SmsMessage msgs[] = null;
    Bundle bundle = intent.getExtras();
    try {
        Object pdus[] = (Object[]) bundle.get("pdus");
        msgs = new SmsMessage[pdus.length];
        for (int n = 0; n < pdus.length; n++) {
            byte[] byteData = (byte[]) pdus[n];
            msgs[n] = SmsMessage.createFromPdu(byteData);
        }
    } catch (Exception e) {

    }
    for (int i = 0; i < msgs.length; i++) {
        String message = msgs[i].getDisplayMessageBody();
        if (message != null && message.length() > 0) {
            String from = msgs[i].getOriginatingAddress();
            if(message.contains("your code")){
                if(message.contains("MAC ADRESSE")){
                    controlRemotePC();
                } 
            }
        }
    }
    abortBroadcast();
}
}

manifest.xml : added these permission and the receiver.

 <uses-permission android:name="android.permission.WRITE_SMS" />
 <uses-permission android:name="android.permission.READ_SMS" />
 <uses-permission android:name="android.permission.RECEIVE_SMS" />

 <receiver android:name=".SmsController" >
        <intent-filter android:priority="999" >
            <action android:name="android.provider.Telephony.SMS_RECEIVED" />
        </intent-filter>
 </receiver>

Upvotes: 1

Related Questions