Permissionsdispatcher: Multiple permissions broken on Kotlin

Created on 16 Jan 2018  路  6Comments  路  Source: permissions-dispatcher/PermissionsDispatcher

Overview

  • Needs to be revised to use a proper array rather than String[] for the annotation since it's a dealbreaker for Kotlin. Curly braces = lambda in Kotlin

Expected

/**
 * Register some methods which permissions are needed.
 */
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.CLASS)
public @interface NeedsPermission {
   Array<String> value();

    int maxSdkVersion() default 0;
}

or similar.

Actual

/**
 * Register some methods which permissions are needed.
 */
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.CLASS)
public @interface NeedsPermission {
    String[] value();

    int maxSdkVersion() default 0;
}

Environment

  • 3.1.0
inquiry

Most helpful comment

WRITE_SETTINGS and SYSTEM_ALERT_WINDOW are special cases that cannot be part of the "ordinary permission flow", because you need to redirect the user to the device settings for these permissions. That's why we raise that exception when you mix them with "normal" permission requests.

See also this reference on the Android docs.

All 6 comments

you can use as below

@NeedsPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE)
fun onClickImageShare() {
}

@cuichanghao This will not trigger proper helper methods callers..
OnShowRationale or OnPermissionDenied or OnNeverAskAgain callers are not generated for a multiple declared NeedsPermission function

Sorry I haven't understood the problem. The reason we use Java for annotation is we support both Java and Kotlin for now. Does that makes sense?

ref:
https://github.com/permissions-dispatcher/PermissionsDispatcher/blob/ab94c389673aae3fc3a304b41a40e8373866f852/sample-kotlin/src/main/kotlin/permissions/dispatcher/samplekotlin/MainActivity.kt#L65

Let me close the issue since there's only an inadequate info.

@NeedsPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.WRITE_SETTINGS)
    fun ringtoneApply(){

Using this in kotlin throws Error:

e: [kapt] An exception occurred: permissions.dispatcher.processor.exception.MixPermissionTypeException: Method 'ringtoneApply()' defines 'android.permission.WRITE_SETTINGS' with other permissions at the same time.

WRITE_SETTINGS and SYSTEM_ALERT_WINDOW are special cases that cannot be part of the "ordinary permission flow", because you need to redirect the user to the device settings for these permissions. That's why we raise that exception when you mix them with "normal" permission requests.

See also this reference on the Android docs.

Was this page helpful?
0 / 5 - 0 ratings