2

I followed the simple steps to ask for multiple permissions at once, here is my code for the permission request:

class MainActivity : AppCompatActivity() {
    private val permissionCode = 100
}

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)

    getPermissions()
}

fun getPermissions() {
    ActivityCompat.requestPermissions(
        this,
        arrayOf(Manifest.permission.NFC, Manifest.permission.INTERNET),
        permissionCode
    )
}

override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
        when (requestCode) {
            permissionCode -> {
                if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                    // Permission granted
                    Toast.makeText(this, "Permissions granted", Toast.LENGTH_SHORT).show()
                } else {
                    // Permission denied
                    Toast.makeText(this, "Permission denied", Toast.LENGTH_SHORT).show()
                }
            }
        }
    }

When I am starting the app I dont get any dialog to accept or deny the permissions and just get the toast "Permissions granted" but if I check the permissions in the app info I dont see any permissions granted. What I am doing wrong? Can someone help me?

rm -rf
  • 968
  • 1
  • 12
  • 28

1 Answers1

4

Neither INTERNET nor NFC are permissions that need to be requested at runtime. Just having them in the manifest (via <uses-permission> elements) is sufficient.

Only permissions with a protection level of dangerous need to be requested at runtime — this table lists those. INTERNET and NFC are normal permissions, not dangerous.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • 1
    @rm-rf Here is an example of adding these types of permissions to the manifest file: https://stackoverflow.com/a/2169311/8685250 – Hayes Roach Jul 10 '19 at 20:35