Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Real" testing of sms receiver

I have a SmsReceiverwhich I would like to test for real on a device, however I'm not willing to send a bunch of real sms's to my device that stacks up my phone bills;-)

So I thought that I must be able to kick of an intent with action RECEIVED_SMS, sms data and all other stuff needed to send a sms. After a quick tour on google I ended up here: http://blog.dev001.net/post/14085892020/android-generate-incoming-sms-from-within-your-app. I took some ideas from this post and made my killer android app for creating and "sending" sms on the device for test purpose, and I must say that it worked like a charm, except that my receivers onReceive isn't invoked, the sent sms just goes directly to the inbox. I know that my receiver works, if I send a real sms to my device it triggers, and if I send an sms from DDMS to an emulator it also triggers, so that should be fine.

So is there any permissions, some Intent.putExtras or other stuff that I miss? Any tips is really helpful and if a could get this to work it would help me a lot in testing and developing of my application.

My receiver in manifest:

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

Permissions in manifest(receiving application):

<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.WRITE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.VIBRATE" /> 
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />  

Permissions in manifest(sending application):

<uses-permission android:name="android.permission.BROADCAST_SMS"/>

Should also mention that no errors are showing up in LogCat or in console.

like image 260
Robert Avatar asked Mar 10 '14 20:03

Robert


2 Answers

This is how my receiver looks like in the manifest :

<receiver android:name="com.mike.broadcastexample.BroadcastReceiverClass" android:exported="true" > 
            <intent-filter android:priority="999" > 
                <action android:name="android.provider.Telephony.SMS_RECEIVED" />
            </intent-filter> 
        </receiver>

The only thing I am doing extra is that I have set the android:priority to 999 and added android:exported="true"

These were the only permissions I used for the app:

    <uses-permission android:name="android.permission.WRITE_SMS" />
    <uses-permission android:name="android.permission.READ_SMS" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.SEND_SMS" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.RECEIVE_SMS" />

I was having the same problem with my application too and it was HTC ONE which has Android 4.3 but after making some changed to this receiver, its working absolutely perfect.

You can give it a try too.

like image 191
mike20132013 Avatar answered Oct 01 '22 23:10

mike20132013


Use the following receiver declaration also make sure that your SMsReceiver exists in main package or else provide complete path "*path/SmsReceiver*" here path means the complete package path.

 <receiver
            android:name=".SmsReceiver"
            android:exported="true"
            android:permission="android.permission.BROADCAST_SMS" >
            <intent-filter android:priority="5822" >
                <action android:name="android.provider.Telephony.SMS_RECEIVED" />
            </intent-filter>
        </receiver>

Also all permissions seems to be fine , just if your sending SMS too , just include

<uses-permission android:name="android.permission.SEND_SMS" />
like image 26
Arpit Garg Avatar answered Oct 02 '22 00:10

Arpit Garg