permissions-dispatcher / PermissionsDispatcher

A declarative API to handle Android runtime permissions.
https://github.com/permissions-dispatcher/PermissionsDispatcher
Apache License 2.0
11.23k stars 1.44k forks source link

When it runs on android Q device, the authorization window pops up. Before clicking to confirm authorization, it reaches the annotation method of authorization passing #651

Closed wangyangke closed 4 years ago

wangyangke commented 4 years ago

FAQs


Overview

Added a permission request to android Q devices and passed @needspermission without selecting authorization

Expected

Enter the @needspermission annotation method with authorization

Actual

Entered the @needspermission annotation method without authorization

Environment

-com.github.hotchemi:permissionsdispatcher:3.1.0

Reproducible steps

-After adding libry, it will run on android Q device, and the authorization window will pop up. Before clicking to confirm authorization, it will go to the annotation method of authorization

hotchemi commented 4 years ago

Could you share pseudo code?

wangyangke commented 4 years ago

`package com.onesports.score.ui

import android.Manifest import android.annotation.SuppressLint import android.app.AlertDialog import android.app.Dialog import android.content.Intent import android.net.Uri import android.os.Build import android.os.Bundle import android.view.View import android.widget.TextView import com.crashlytics.android.Crashlytics import com.google.android.gms.tasks.OnCompleteListener import com.google.firebase.iid.FirebaseInstanceId import com.onesports.score.R import com.onesports.score.common.AppConfig import com.onesports.score.di.Injectable import com.onesports.score.ui.base.AbstractActivity import com.onesports.score.utils.LogUtils import com.onesports.score.utils.statusbar.StatusBarUtil import io.fabric.sdk.android.Fabric import permissions.dispatcher.NeedsPermission import permissions.dispatcher.OnNeverAskAgain import permissions.dispatcher.OnPermissionDenied import permissions.dispatcher.RuntimePermissions

@RuntimePermissions class LaunchActivity : AbstractActivity(), Injectable { val TAG = "LaunchActivity" var dialog: Dialog? = null var isNeverAsk = false override fun setStatusBar() { StatusBarUtil.setTranslucent(this) } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) Fabric.with(this, Crashlytics()) FirebaseInstanceId.getInstance().instanceId .addOnCompleteListener(OnCompleteListener { task -> if (!task.isSuccessful) { LogUtils.w(TAG, "getInstanceId failed", task.exception) return@OnCompleteListener } // Get new Instance ID token val token = task.result?.token // Log and toast sp { putString(AppConfig.SpModel.SP_FCM_TOKEN,token) } })

    initWithPermissionCheck()
}

@SuppressLint("MissingPermission")
@NeedsPermission(value = [Manifest.permission.WRITE_EXTERNAL_STORAGE,Manifest.permission.READ_EXTERNAL_STORAGE])
fun init() {
    goMainActivity()
}

private fun goMainActivity() {
    intent.setClass(this, MainNavigationActivity::class.java)
    startActivity(intent)
    finish()
}

@SuppressLint("NeedOnRequestPermissionsResult")
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults)
    onRequestPermissionsResult(requestCode, grantResults)
}

@OnPermissionDenied(value = [Manifest.permission.WRITE_EXTERNAL_STORAGE,Manifest.permission.READ_EXTERNAL_STORAGE])
fun onPermissionDenied() {
    if (Build.VERSION.SDK_INT >=29) {
        goMainActivity()
    } else {
        openDialog()
    }
}

@OnNeverAskAgain(value = [Manifest.permission.WRITE_EXTERNAL_STORAGE,Manifest.permission.READ_EXTERNAL_STORAGE])
fun onPermissionNever() {
    isNeverAsk = true
     if (Build.VERSION.SDK_INT >=29) {
         goMainActivity()
    } else {
        openDialog()
    }
}

private fun openDialog() {
    var dialogView: View
    val dialogBuilder = AlertDialog.Builder(this, R.style.style_popup)
    val inflater = this.layoutInflater
    dialogView = inflater.inflate(R.layout.dialog_common, null)
    dialogBuilder.setView(dialogView)
    if (dialog == null) {
        dialog = dialogBuilder.create()
    }
    var confirm = dialogView.findViewById<TextView>(R.id.btn_dialog_confirm)
    var cancel = dialogView.findViewById<TextView>(R.id.btn_dialog_cancel)
    confirm.text = "OK"
    cancel.text = getString(R.string.data_str7)
    dialogView.findViewById<TextView>(R.id.tv_content).setText(R.string.app_comm04)
    cancel.setOnClickListener {
        finish()
        System.exit(0)
    }
    confirm.setOnClickListener {
        if (isNeverAsk) {
            toSelfSetting()
            isNeverAsk = false
        } else {
            initWithPermissionCheck()
        }
    }
    dialog?.setCanceledOnTouchOutside(false)
    dialog?.show()
}

fun toSelfSetting() {
    val mIntent = Intent()
    mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
    mIntent.action = "android.settings.APPLICATION_DETAILS_SETTINGS"
    mIntent.data = Uri.fromParts("package", this.packageName, null)
    startActivity(mIntent)
}

} `

hotchemi commented 4 years ago

@wangyangke sorry I don't understand the issue. If you need more help it'd be great if you can attach the video to show the actual problem or give us more detail what's the problem actually is.