ligi ligi - 5 months ago 72
Android Question

permissionsdispatcher and multiple @NeedsPermission's with kotlin

For one permission I can use permissionsdispatcher in java and kotlin - but when it comes to multiple permissions like this:

@NeedsPermission({Manifest.permission.BLUETOOTH_ADMIN,Manifest.permission.BLUETOOTH})


I get a problem on kotlin - it does not accept more than one parameter there - works fine with java

Answer
@NeedsPermission(value = arrayOf(Manifest.permission.BLUETOOTH_ADMIN,Manifest.permission.BLUETOOTH))

In java @NeedsPermission({...}) the curly brackets {...} is just a shorthand for creating an array. In kotlin you must explicitly say that it is an array.