Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Android RECEIVE_SMS

  • 11-11-2012 03:10PM
    #1
    Registered Users, Registered Users 2 Posts: 7,460 ✭✭✭


    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, Registered Users 2 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, Registered Users 2 Posts: 7,460 ✭✭✭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, Registered Users 2 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, Registered Users 2 Posts: 7,460 ✭✭✭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, Registered Users 2 Posts: 7,460 ✭✭✭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