Since Android 6.0 (API level 23) you have to request the permissions at runtime. Most application do that when the user is starting the app for the first time.
To check if you have the permission already, use
int permissionCheck = ContextCompat.checkSelfPermission(thisActivity, Manifest.permission.READ_SMS);
to check if you can read SMS.
Return will be PackageManager.PERMISSION_GRANTED
if the app has the permission already, else it will return PackageManager.PERMISSION_DENIED
.
To request permission, use
ActivityCompat.requestPermissions(thisActivity, new String[]{Manifest.permission.READ_SMS}, MY_PERMISSIONS_REQUEST_READ_CONTACTS);
where MY_PERMISSIONS_REQUEST_READ_CONTACTS
is an app defined int constant.
The corresponding documentation will give more detail about this.
Please note: You need to define the corresponding <uses-permission>
elements in your Manifest and then request the permission at runtime.
To work around this problem, simply drop the targeted SDK version below 23.