Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⚡️ [Android] Always declare READ_EXTERNAL_STORAGE on Android #874

Merged
merged 4 commits into from
Nov 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ that can be found in the LICENSE file. -->

### Improvements

- Always declare `READ_EXTERNAL_STORAGE` permission on Android. (#874)
- Upgrade Glide and Kotlin libraries version. (#872)
- Avoid using file-based saving methods on Android. (#871)
- Use `ContentUris` for retrieving Media URIs on Android. (#870)
Expand Down
3 changes: 1 addition & 2 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.fluttercandies.photo_manager">

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="32" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

</manifest>
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@file:Suppress("DEPRECATION")

package com.fluttercandies.photo_manager.permission

import android.Manifest
Expand Down Expand Up @@ -120,14 +118,12 @@ class PermissionsUtils {
private fun checkPermissions(vararg permissions: String): Boolean {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
resetStatus()
for (i in permissions.indices) {
// 检查权限
if (mActivity!!.checkSelfPermission(permissions[i]) == PackageManager.PERMISSION_DENIED) {
needToRequestPermissionsList.add(permissions[i])
for (p in permissions) {
if (mActivity!!.checkSelfPermission(p) == PackageManager.PERMISSION_DENIED) {
return false
}
}
// 全部权限获取成功返回 true,否则返回 false
return needToRequestPermissionsList.isEmpty()
return true
}
return true
}
Expand Down Expand Up @@ -272,10 +268,18 @@ class PermissionsUtils {

fun havePermissionInManifest(context: Context, permission: String): Boolean {
val applicationInfo = context.applicationInfo
val packageInfo = context.packageManager.getPackageInfo(
applicationInfo.packageName,
PackageManager.GET_PERMISSIONS
)
val packageInfo = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
context.packageManager.getPackageInfo(
applicationInfo.packageName,
PackageManager.PackageInfoFlags.of(PackageManager.GET_PERMISSIONS.toLong())
)
} else {
@Suppress("DEPRECATION")
context.packageManager.getPackageInfo(
applicationInfo.packageName,
PackageManager.GET_PERMISSIONS
)
}
return packageInfo.requestedPermissions.contains(permission)
}
}
}