0

I am trying to receive SMS using Broadcast receiver in marshmallow nexus device. I am using target and compile SDK version 23. I know using target SDK version lower than 23 works but I don't like that solution. If there is a way to read SMS in marshmallow using target SDK version 23+ please answer.

public class SmsReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        Log.d(SmsReceiver.class.getSimpleName(), "SMS received");
    }
}

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.hello_receive_sms.app" >
    <uses-permission android:name="android.permission.READ_SMS"/>
    <uses-permission android:name="android.permission.RECEIVE_SMS"/>
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name">
        <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>
        <receiver android:name="com.example.hello_receive_sms.app.SmsReceiver">
            <intent-filter>
                <action android:name="android.provider.Telephony.SMS_RECEIVED"/>
            </intent-filter>
        </receiver>
    </application>

</manifest>

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.example.hello_receive_sms.app"
        minSdkVersion 9
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_6
        targetCompatibility JavaVersion.VERSION_1_6
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
Shahidul
  • 2,997
  • 1
  • 21
  • 20
  • 2
    Possible duplicate of [Can't Get the Permission](http://stackoverflow.com/questions/32635704/cant-get-the-permission) – Mike M. Jan 14 '16 at 12:39

1 Answers1

1

You need a permission. For api level 23+, google reworked the permission system so the app user can grant and revoke permissions after installing your app.

Setting permissions in manifest is only the first step. You should read a bit about "runtime permissions in android marshmallow":

http://developer.android.com/training/permissions/requesting.html

Jörn Buitink
  • 2,906
  • 2
  • 22
  • 33