Resolution denied even after adding correct permission to manifest

I am developing an application that listens for incoming sms. I added permission:

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

      

to the application manifest. And yes, it is not inside the receiver tag.

I am trying to test an application by sending sms from one emulator to another. My logcat gets the following entry:

WARN/ActivityManager(66): Permission Denial: receiving Intent { act=android.provider.Telephony.SMS_RECEIVED (has extras) } to com.android.LUC requires android.permission.RECEIVE_SMS due to sender com.android.phone (uid 1001)

      

The weird part is that when I test the app on an emulator running Android 3.2, it works great!

App Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.android.sms"
      android:versionCode="1"
      android:versionName="1.0">

    <uses-sdk android:minSdkVersion="8" />
    <uses-permission android:name="android.permission.RECEIVE_SMS" />
    <uses-permission android:name="android.permission.READ_SMS" />

    <application android:icon="@drawable/icon" android:label="@string/app_name" android:permission="android.permission.RECEIVE_SMS">
        <activity android:name=".TestSMSReceiveActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

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

    </application>
</manifest>

      

mysmstestcall is the broadcastreceiver class and testSMSReceiveActivity is the main activity. The application does not receive the message in the emulator running Android 2.2. Please, help!

+3


source to share


1 answer


Ok, the problem is in your manifest. My working SMS recipient has the following manifest entry:

<receiver
    android:name=".IncomingSmsBroadcastReceiver"
    android:enabled="true"
    android:exported="true">
    <intent-filter>
        <action android:name="android.provider.Telephony.SMS_RECEIVED" />
    </intent-filter>
</receiver>

      

You don't need the android: permission attribute on the receiver. You just need the following permissions to receive broadcasts and view the content of a message:



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

      

The most commonly overlooked is android:exported="true"

when declaring a recipient, which is required when you receive a broadcast that is originating from outside your own application. Needless to say, the default for this property is "false". Happy SMS receiving.

+5


source







All Articles