0

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?)?

vij
  • 143
  • 1
  • 2
  • 18
  • And Android phones will have access to the pc's local ethernet... how? Unless your phone has supports a usb ethernet adapter, you're not going to be getting access to the local network. – Marc B May 27 '12 at 05:21
  • 1
    @MarcB: If the PC is connected via ethernet to the wireless router, and the phone is on the same wi-fi network, they would be able to communicate, right? – Ayush May 27 '12 at 05:29
  • you can execute the code whenever sms is received from following link http://stackoverflow.com/questions/1944102/android-sms-receiver-not-working – Nitin May 27 '12 at 15:02

1 Answers1

1

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>
113408
  • 3,364
  • 6
  • 27
  • 54
  • 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 that phone?)? – vij May 27 '12 at 13:19
  • Yes it is. in your application you have to set in the manifest the priority of your broadcastreceiver to 999. you can use also the brodcastreceiver.abort() to don't show it in your inboxs. Only your application will receive your SMS – 113408 May 27 '12 at 20:37
  • Hi one thing to mention, the application should automatically start running when user switch on the mobile phone, and the user should not have any control over the application. That is if the message is received, the message should be read, some work is carried out and the message should be deleted. If some user at remote place uses mobile phone, at first glace, the user should not be informed anything about the background application running. is it possible to develop this kind of application? – vij May 28 '12 at 02:26
  • Yes it is. when you `abort()` the BroadcastReceiver for the SMS, the other application will not receive any notification about incoming SMS and the user will not be informed about anything. With the above code you can intercept the SMS and do your work . Don't forget to abort the BroadcastReceiver. – 113408 May 28 '12 at 08:17
  • hi Hamza Karmouda,is it possible to send message to a particular port in android(this is because your code receives all the messages that are sent to inbox from other devices also. But i need some code, which hides only the communication messages between app A and app B only and that does not interfere in normal messaging capabilities. – vij Jun 01 '12 at 07:20
  • @vij I don't think you can filtre by port. you can only check if the message contains a string. in your case from app A send a sms containing for example a `string` "AppA" and filter with the code given above – 113408 Jun 01 '12 at 16:00