0

My application is unable to catch android.provider.Telephony.SMS_RECEIVED , I tried changing priority but still not working .

AndroidManifest.xml `

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

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme"
    >
    <receiver android:enabled="true" android:exported="true" android:name="com.example.dexter.texter.MyReceiver">
        <intent-filter android:priority="2147483647">
            <action android:name="android.provider.Telephony.SMS_RECEIVED"/>
        </intent-filter>
    </receiver>
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

</application>

`

MyReceiver.java`

@Override
public void onReceive(Context context, Intent intent) {
    Toast.makeText(context, "Broadcasted", Toast.LENGTH_LONG).show();
}`
Dexter
  • 11
  • 1
  • 3
  • @Dexter- on which OS version you are testing? – Rohitashv jain May 05 '16 at 05:35
  • where is your java code? – Nirav Ranpara May 05 '16 at 05:36
  • What's your `targetSdkVersion`, and which version of Android are you testing under? Have you launched your `MainActivity` at least once after installation to bring it out of the _stopped_ state? Is your Receiver in the same folder as `MainActivity`? – Mike M. May 05 '16 at 05:36
  • I am testing it on Marshmallow and MyReceiver is in the same package of MainActivity – Dexter May 05 '16 at 05:41
  • 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. May 05 '16 at 05:41
  • @NiravRanpara I have don't have any other java code except MainActivity – Dexter May 05 '16 at 05:44
  • In this run time permission problem when ever you start your app please ask for permission if not granted. for testing purpose go in app settings and manually grant the permission. – Rohitashv jain May 05 '16 at 05:46
  • Thanks ... all I totally forgot to check for Dangerous Permission now my problem is resolved . – Dexter May 05 '16 at 09:33

1 Answers1

0

You want to use one of dangerous permissions.

If your APP is 23+ you should have the <uses-permission> and also do checking in your code by calling ContextCompat.checkSelfPermission() and if permission is not granted request for it in your code by calling ActivityCompat.requestPermissions()

Read documentation about requesting permissions at run time in Android 6.0+.

Fiil
  • 1,680
  • 11
  • 11