Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Android RECEIVE_SMS

Options
  • 11-11-2012 3:10pm
    #1
    Registered Users Posts: 7,398 ✭✭✭


    I am trying to build my first Android application but have run into difficulty.

    I am trying to intercept text messages from a certain number and do something with them...but I can't seem to manage to intercept the SMSs at all....here's the code so far

    SMSReceiveActivity.java
    package sms.receive.sample;
    import android.content.*;
    import android.os.Bundle;
    import android.telephony.*;
    import android.util.Log;
    import android.widget.Toast;
    
    public class SMSReceiveActivity extends BroadcastReceiver {
    
    private static final String TAG = "Message recieved";
    
     @Override
     public void onReceive(Context context, Intent intent) {   
    
         Bundle pudsBundle = intent.getExtras();
         Object[] pdus = (Object[]) pudsBundle.get("pdus");
         SmsMessage messages =SmsMessage.createFromPdu((byte[]) pdus[0]);    
         Log.i(TAG,  messages.getMessageBody());
         Toast.makeText(context, "SMS Received : "+messages.getMessageBody(),
         Toast.LENGTH_LONG).show();
     }
    }
    

    AndroidManifest.xml
    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="sms.receive.sample"
        android:versionCode="1"
        android:versionName="1.0" >    
     <uses-sdk android:minSdkVersion="15" />
     <uses-permission android:name="android.permission.RECEIVE_SMS" /> 
     <application icon="@drawable/ic_launcher" label="@string/app_name">
         <receiver 
             android:name=".SMSReceiveActivity" 
             android:exported="true" 
             android:enabled="true">
             <intent-filter android:priority="999">
                 <action android:name="android.provider.Telephony.SMS_RECEIVED" /> 
             </intent-filter>
         </receiver>
    </application>
    </manifest>
    

    When I send (telnet) an SMS to the AVD, I get the nofication in the drawer but not the Toast. I've tried on my phone too and I get the same....
    Any help much appreciated.


Comments

  • Registered Users Posts: 18,272 ✭✭✭✭Atomic Pineapple


    Try using the full package name to the receiver rather than just .SMSReceiveActivity. Only had a quick look but everything looks OK with it.


  • Registered Users Posts: 7,398 ✭✭✭fletch


    draffodx wrote: »
    Try using the full package name to the receiver rather than just .SMSReceiveActivity. Only had a quick look but everything looks OK with it.
    Thanks...just tried that but no change :(


  • Registered Users Posts: 18,272 ✭✭✭✭Atomic Pineapple


    fletch wrote: »
    Thanks...just tried that but no change :(

    Have you tried on an actual device? I know the emulator can be funny with things like this.


  • Registered Users Posts: 7,398 ✭✭✭fletch


    draffodx wrote: »
    Have you tried on an actual device? I know the emulator can be funny with things like this.
    Yeh I tried on my SGSII with ICS


  • Registered Users Posts: 7,398 ✭✭✭fletch


    Found the problem....I didn't have an Activity that the user could launch...:eek:
    http://stackoverflow.com/questions/11865434/android-broadcastreceiver-wont-work?rq=1


  • Advertisement
  • Closed Accounts Posts: 19,777 ✭✭✭✭The Corinthian


    fletch wrote: »
    I am trying to intercept text messages from a certain number and do something with them...
    You might want to set your android:priority higher, if you want to intercept the message before other apps do.


Advertisement