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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Android RECEIVE_SMS

  • 11-11-2012 2:10pm
    #1
    Registered Users, Registered Users 2 Posts: 7,423 ✭✭✭


    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,423 ✭✭✭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,423 ✭✭✭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,423 ✭✭✭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