1

I know this is a question that is asked a lot on here, but I have the most barebones implementation of an SMS BroadcastReceiver in my Android maps app and it will not fire no matter what I've tried. I just wiped my phone, so no other apps should interfere with the receiver. In fact, I tried my friend's app who uses the same feature, but his implementation worked and my did not, despite the code being almost exactly the same. I know it's a shot in the dark, but I was wondering if you might happen to know why the following code is not executing.

AndroidManifest.xml

<uses-feature android:name="android.hardware.telephony" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.WRITE_SMS" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

    <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="@string/google_maps_key" />

    <activity
        android:name=".MapsActivity"
        android:label="@string/title_activity_maps">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

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

</application>

SMSReceiver

public class SMSReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.d("msg", "called");
    }
}

The minimum SDK is 18 and the target is 23. Thanks for all your help!

Nickersoft
  • 684
  • 1
  • 12
  • 30
  • 1
    Which Android version is your phone running? Is your Receiver in the same folder as `MapsActivity`? Have you launched your app at least once after installation to bring it out of the _stopped_ state? – Mike M. Apr 25 '16 at 22:36
  • Probably should have specified.. I am running Android 6.0.1 on a Nexus 6. And yes, they are both in the same folder, and both are in the same package. As for the last question... I'm not sure. I pressed the "debug" button in Android Studio to launch the app. I've also closed the installed app on my phone and reopened it. The receiver is still not firing. – Nickersoft Apr 25 '16 at 23:22
  • Possible duplicate of [Android permission doesn't work even if I have declared it](http://stackoverflow.com/questions/32635704/android-permission-doesnt-work-even-if-i-have-declared-it) – Mike M. Apr 25 '16 at 23:26

1 Answers1

0

Fixed! For some reason, changing the target SDK from 23 to 19 worked :)

Nickersoft
  • 684
  • 1
  • 12
  • 30