0

I'm trying to build an app, which emails a picture after an sms is sent to the phone. So I have been following this Tutorial with no success. When sending an sms to a real phone in debug mode, nothing happens. I've been trying to debug the app but the broadcastreceiver doesn't even launch.

public class SmsReciever extends BroadcastReceiver {

final SmsManager sms = SmsManager.getDefault();
@Override
public void onReceive(Context context, Intent intent) {
Log.i(TAG, "started…");
final Bundle bundle = intent.getExtras();
    try {
        if (bundle != null) {
            final Object[] pdusObj = (Object[]) bundle.get("pdus");

            for (int i = 0; i < pdusObj.length; i++) {
                SmsMessage currentMessage = SmsMessage.createFromPdu((byte[]) pdusObj[i]);
                String phoneNumber = currentMessage.getDisplayOriginatingAddress();

                String senderNum = phoneNumber;
                String message = currentMessage.getDisplayMessageBody();

                Log.i("SmsReciever", "senderNum: " + senderNum + "; message" + message);

                //action

            }
        }
    } catch (Exception e){
        Log.e("SmsReceiver", "Exception sms Reciever" + e);
    }

The Logcat does not print any errors or logs of that code bit. My manifest file looks like so:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tapplic.adrianopaulus.smscamera" >

<uses-permission android:name="android.permission.WRITE_SMS"/>
<uses-permission android:name="android.permission.READ_SMS"/>
<uses-permission android:name="ANDROID.PERMISSION.RECEIVE_SMS"></uses-permission>
<uses-permission android:name="android.permission.SEND_SMS"></uses-permission>

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

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <receiver android:name=".SmsReciever" >
        <intent-filter>
            <action android:name="android.provider.Telephony.SMS_RECIEVED" />
        </intent-filter>
    </receiver>
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

</manifest>

I have also looked at these problems on stackoverflow: Android - SMS Broadcast receiver
Android SMS reciever not working

Cœur
  • 37,241
  • 25
  • 195
  • 267
Adrian
  • 360
  • 1
  • 11
  • 21

1 Answers1

0

Permission strings are case-sensitive. You have:

<uses-permission android:name="ANDROID.PERMISSION.RECEIVE_SMS"></uses-permission>

You should have:

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

EDIT: Add additional problem description:

Also, the ACTION in your <intent-filter> is misspelled. You have:

<action android:name="android.provider.Telephony.SMS_RECIEVED" />

However, this should be:

<action android:name="android.provider.Telephony.SMS_RECEIVED" />

The rule in English is "I before E, except after C" :-)

David Wasser
  • 93,459
  • 16
  • 209
  • 274