-1

I am developing a small application for sending SMS for Android. When you install an .apk Android 4.4 asks for permission to send SMS messages from the device. But Android 7 does not ask any permissions at all. However, you need to turn on SMS send permission manually in settings to make application work properly.

Is there any way to show permissions during install process on all Android systems?

Luca H
  • 123
  • 10
  • For android 7 you need to get permission from the user during runtime. – Rakesh Polo Nov 08 '17 at 07:25
  • https://stackoverflow.com/questions/32635704/android-permission-doesnt-work-even-if-i-have-declared-it/41957460#41957460 Give permission run time using above link – user7176550 Nov 08 '17 at 07:26

1 Answers1

2

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.

Luca H
  • 123
  • 10