我正在尝试使用QuickPermissions-Kotlin,但似乎不知道如何调用它。
我有:
class ScanFragment : ListFragment() {
// ...
private fun scanLeDevice(enable: Boolean) = runWithPermissions(
Manifest.permission.BLUETOOTH_ADMIN,
Manifest.permission.ACCESS_FINE_LOCATION
) {
// ...
}
// ...
}
(我的完整资料是https://gist.github.com/astronouth7303/e676fb42644ed036f4af2f9516b556f2)
runWithPermissions()
声明为:
fun Context?.runWithPermissions(
vararg permissions: String,
options: QuickPermissionsOptions = QuickPermissionsOptions(),
callback: () -> Unit
): Any? {
return runWithPermissionsHandler(this, permissions, callback, options)
}
fun Fragment?.runWithPermissions(
vararg permissions: String,
options: QuickPermissionsOptions = QuickPermissionsOptions(),
callback: () -> Unit
): Any? {
return runWithPermissionsHandler(this, permissions, callback, options)
}
但是我得到了错误:
未解决的参考。由于接收器类型不匹配,以下候选者都不适用:
在
public fun Context?.runWithPermissions(vararg permissions: String, options: QuickPermissionsOptions = ..., callback: () -> Unit): Any?
中定义的com.livinglifetechway.quickpermissions_kotlin
(要清楚,继承是ScanFragment
-> ListFragment
-> Fragment
-> Object
)
那么当存在Context.runWithPermissions()
时,为什么要尝试在Fragment
内使用Fragment.runWithPermissions()
?
答案 0 :(得分:0)
7天前,runWithPermissions
的{{1}}扩展名似乎已添加到该库中的this commit中。如果您拥有Fragment
之后发布的版本,则使用它的效果很好:
0.2.0
也许您仍在该库的implementation 'com.github.quickpermissions:quickpermissions-kotlin:0.2.0'
版本中,但没有此功能?