其他
PermissionX 1.7发布,全面支持Android 13运行时权限
READ_MEDIA_IMAGES
READ_MEDIA_VIDEO
READ_MEDIA_AUDIO
POST_NOTIFICATIONS
BODY_SENSORS_BACKGROUND
NEARBY_WIFI_DEVICES
<manifest ...>
<!-- Required only if your app targets Android 13. -->
<!-- Declare one or more the following permissions only if your app needs
to access data that's protected by them. -->
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
<!-- Required to maintain app compatibility. -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="32" />
<application ...>
...
</application>
</manifest>
val requestList = ArrayList<String>()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
requestList.add(Manifest.permission.READ_MEDIA_IMAGES)
requestList.add(Manifest.permission.READ_MEDIA_AUDIO)
requestList.add(Manifest.permission.READ_MEDIA_VIDEO)
}
if (requestList.isNotEmpty()) {
PermissionX.init(activity)
.permissions(requestList)
.onExplainRequestReason { scope, deniedList ->
val message = "PermissionX需要您同意以下权限才能正常使用"
scope.showRequestReasonDialog(deniedList, message, "Allow", "Deny")
}
.request { allGranted, grantedList, deniedList ->
if (allGranted) {
Toast.makeText(activity, "所有申请的权限都已通过", Toast.LENGTH_SHORT).show()
} else {
Toast.makeText(activity, "您拒绝了如下权限:$deniedList", Toast.LENGTH_SHORT).show()
}
}
}
<manifest ...>
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
<application ...>
...
</application>
</manifest>
PermissionX.init(activity)
.permissions(PermissionX.permission.POST_NOTIFICATIONS)
.onExplainRequestReason { scope, deniedList ->
val message = "PermissionX需要您同意以下权限才能正常使用"
scope.showRequestReasonDialog(deniedList, message, "Allow", "Deny")
}
.request { allGranted, grantedList, deniedList ->
if (allGranted) {
Toast.makeText(activity, "所有申请的权限都已通过", Toast.LENGTH_SHORT).show()
} else {
Toast.makeText(activity, "您拒绝了如下权限:$deniedList", Toast.LENGTH_SHORT).show()
}
}
<manifest ...>
<uses-permission android:name="android.permission.BODY_SENSORS"/>
<uses-permission android:name="android.permission.BODY_SENSORS_BACKGROUND"/>
<application ...>
...
</application>
</manifest>
val requestList = ArrayList<String>()
requestList.add(Manifest.permission.BODY_SENSORS)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
requestList.add(Manifest.permission.BODY_SENSORS_BACKGROUND)
}
PermissionX.init(activity)
.permissions(requestList)
.onExplainRequestReason { scope, deniedList ->
val message = "PermissionX需要您同意以下权限才能正常使用"
scope.showRequestReasonDialog(deniedList, message, "Allow", "Deny")
}
.request { allGranted, grantedList, deniedList ->
if (allGranted) {
Toast.makeText(activity, "所有申请的权限都已通过", Toast.LENGTH_SHORT).show()
} else {
Toast.makeText(activity, "您拒绝了如下权限:$deniedList", Toast.LENGTH_SHORT).show()
}
}
<manifest ...>
<uses-permission android:name="android.permission.NEARBY_WIFI_DEVICES"/>
<application ...>
...
</application>
</manifest>
PermissionX.init(activity)
.permissions(Manifest.permission.NEARBY_WIFI_DEVICES)
.onExplainRequestReason { scope, deniedList ->
val message = "PermissionX需要您同意以下权限才能正常使用"
scope.showRequestReasonDialog(deniedList, message, "Allow", "Deny")
}
.request { allGranted, grantedList, deniedList ->
if (allGranted) {
Toast.makeText(activity, "所有申请的权限都已通过", Toast.LENGTH_SHORT).show()
} else {
Toast.makeText(activity, "您拒绝了如下权限:$deniedList", Toast.LENGTH_SHORT).show()
}
}
repositories {
google()
mavenCentral()
}
dependencies {
implementation 'com.guolindev.permissionx:permissionx:1.7.1'
}
https://github.com/guolindev/PermissionX
欢迎关注我的公众号
学习技术或投稿
长按上图,识别图中二维码即可关注