Closed wangyangke closed 4 years ago
Could you share pseudo code?
`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)
}
} `
@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.
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