우선 build.gradle(Module : app) 에 implementation 'io.github.ParkSangGwon:tedpermission-normal:3.3.0' 적용시키기
매니페스트에 uses-permission android:name="android.permission.CALL_PHONE" 적용하기
override fun setupEvents() {
binding.callPhoneBtn.setOnClickListener {
val permissionListener = object : PermissionListener {
override fun onPermissionGranted() {
val myUri = Uri.parse("tel:${mStoreData.phoneNumber}")
val myIntent = Intent(Intent.ACTION_CALL, myUri)
startActivity(myIntent)
}
override fun onPermissionDenied(deniedPermissions: MutableList<String>?) {
Toast.makeText(mContext, "전화 연결 권한이 없습니다.", Toast.LENGTH_SHORT).show()
}
}
TedPermission.create() // 변경된 부분
.setPermissionListener(permissionListener)
.setDeniedMessage("[설정] 에서 전화 권한을 켜주세요.")
.setPermissions(Manifest.permission.CALL_PHONE)
.check()
}
}