From 67f9ba9d8c282116b1aaaccda270d51c8c63a3e5 Mon Sep 17 00:00:00 2001 From: Alex Li Date: Mon, 15 Jul 2024 15:06:44 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Do=20not=20require=20`WRITE=5FEX?= =?UTF-8?q?TERNAL=5FSTORAGE`=20if=20not=20declared=20in=20the=20manifest?= =?UTF-8?q?=20with=20Android=2029-=20(#1158)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Caijinglong Co-authored-by: Caijinglong --- CHANGELOG.md | 6 ++++ android/src/main/AndroidManifest.xml | 6 ++-- .../photo_manager/core/utils/DBUtils.kt | 1 - .../permission/PermissionDelegate.kt | 6 ++-- .../permission/PermissionsListener.kt | 3 +- .../permission/PermissionsUtils.kt | 5 ---- .../permission/impl/PermissionDelegate19.kt | 2 +- .../permission/impl/PermissionDelegate23.kt | 15 ++++++---- .../permission/impl/PermissionDelegate33.kt | 2 +- .../permission/impl/PermissionDelegate34.kt | 2 +- .../android/app/src/main/AndroidManifest.xml | 7 +++-- example/lib/widget/gallery_item_widget.dart | 28 +++++++++---------- example/pubspec.yaml | 2 +- example_ohos/pubspec.yaml | 2 +- pubspec.yaml | 2 +- 15 files changed, 45 insertions(+), 44 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aee050d8..a9cf44c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,12 @@ that can be found in the LICENSE file. --> To know more about breaking changes, see the [Migration Guide][]. +## 3.2.2 + +### Fixes + +* Do not require `WRITE_EXTERNAL_STORAGE` if not declared in the manifest with Android 29-. + ## 3.2.1 ### Improvements diff --git a/android/src/main/AndroidManifest.xml b/android/src/main/AndroidManifest.xml index b6022bdc..525e47d6 100644 --- a/android/src/main/AndroidManifest.xml +++ b/android/src/main/AndroidManifest.xml @@ -1,5 +1,5 @@ - - - + diff --git a/android/src/main/kotlin/com/fluttercandies/photo_manager/core/utils/DBUtils.kt b/android/src/main/kotlin/com/fluttercandies/photo_manager/core/utils/DBUtils.kt index ec3a982a..326008f7 100644 --- a/android/src/main/kotlin/com/fluttercandies/photo_manager/core/utils/DBUtils.kt +++ b/android/src/main/kotlin/com/fluttercandies/photo_manager/core/utils/DBUtils.kt @@ -34,7 +34,6 @@ object DBUtils : IDBUtils { val list = ArrayList() val args = ArrayList() val where = option.makeWhere(requestType, args) -// val where = makeWhere(requestType, option, args) val selection = "${MediaStore.MediaColumns.BUCKET_ID} IS NOT NULL $where) GROUP BY (${MediaStore.MediaColumns.BUCKET_ID}" val cursor = context.contentResolver.logQuery( diff --git a/android/src/main/kotlin/com/fluttercandies/photo_manager/permission/PermissionDelegate.kt b/android/src/main/kotlin/com/fluttercandies/photo_manager/permission/PermissionDelegate.kt index 94195382..33c5b926 100644 --- a/android/src/main/kotlin/com/fluttercandies/photo_manager/permission/PermissionDelegate.kt +++ b/android/src/main/kotlin/com/fluttercandies/photo_manager/permission/PermissionDelegate.kt @@ -15,7 +15,6 @@ import com.fluttercandies.photo_manager.util.LogUtils import com.fluttercandies.photo_manager.util.ResultHandler abstract class PermissionDelegate { - protected var resultHandler: ResultHandler? = null private val tag: String @@ -40,7 +39,7 @@ abstract class PermissionDelegate { /** * Check if the permission is in the manifest. */ - private fun havePermissionInManifest(context: Context, permission: String): Boolean { + protected fun havePermissionInManifest(context: Context, permission: String): Boolean { val applicationInfo = context.applicationInfo val packageInfo = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { context.packageManager.getPackageInfo( @@ -174,5 +173,4 @@ abstract class PermissionDelegate { requestType: Int, mediaLocation: Boolean ): PermissionResult - -} \ No newline at end of file +} diff --git a/android/src/main/kotlin/com/fluttercandies/photo_manager/permission/PermissionsListener.kt b/android/src/main/kotlin/com/fluttercandies/photo_manager/permission/PermissionsListener.kt index f87a0cf3..46b0e0e5 100644 --- a/android/src/main/kotlin/com/fluttercandies/photo_manager/permission/PermissionsListener.kt +++ b/android/src/main/kotlin/com/fluttercandies/photo_manager/permission/PermissionsListener.kt @@ -1,7 +1,6 @@ package com.fluttercandies.photo_manager.permission interface PermissionsListener { - fun onGranted(needPermissions: MutableList) fun onDenied( @@ -9,4 +8,4 @@ interface PermissionsListener { grantedPermissions: MutableList, needPermissions: MutableList ) -} \ No newline at end of file +} diff --git a/android/src/main/kotlin/com/fluttercandies/photo_manager/permission/PermissionsUtils.kt b/android/src/main/kotlin/com/fluttercandies/photo_manager/permission/PermissionsUtils.kt index ddab1055..0f9e486c 100644 --- a/android/src/main/kotlin/com/fluttercandies/photo_manager/permission/PermissionsUtils.kt +++ b/android/src/main/kotlin/com/fluttercandies/photo_manager/permission/PermissionsUtils.kt @@ -170,10 +170,6 @@ class PermissionsUtils { if (needToRequestPermissionsList.isNotEmpty()) needToRequestPermissionsList.clear() } - /** - * - */ - /** * 跳转到应用的设置界面 * @@ -206,5 +202,4 @@ class PermissionsUtils { fun getAuthValue(requestType: Int, mediaLocation: Boolean): PermissionResult { return delegate.getAuthValue(context!!, requestType, mediaLocation) } - } diff --git a/android/src/main/kotlin/com/fluttercandies/photo_manager/permission/impl/PermissionDelegate19.kt b/android/src/main/kotlin/com/fluttercandies/photo_manager/permission/impl/PermissionDelegate19.kt index c9575870..0de9c886 100644 --- a/android/src/main/kotlin/com/fluttercandies/photo_manager/permission/impl/PermissionDelegate19.kt +++ b/android/src/main/kotlin/com/fluttercandies/photo_manager/permission/impl/PermissionDelegate19.kt @@ -28,4 +28,4 @@ class PermissionDelegate19 : com.fluttercandies.photo_manager.permission.Permiss ): PermissionResult { return PermissionResult.Authorized } -} \ No newline at end of file +} diff --git a/android/src/main/kotlin/com/fluttercandies/photo_manager/permission/impl/PermissionDelegate23.kt b/android/src/main/kotlin/com/fluttercandies/photo_manager/permission/impl/PermissionDelegate23.kt index 51ddd223..90c81a8e 100644 --- a/android/src/main/kotlin/com/fluttercandies/photo_manager/permission/impl/PermissionDelegate23.kt +++ b/android/src/main/kotlin/com/fluttercandies/photo_manager/permission/impl/PermissionDelegate23.kt @@ -23,7 +23,7 @@ open class PermissionDelegate23 : com.fluttercandies.photo_manager.permission.Pe ) { val permissions = mutableListOf(readPermission, writePermission) - if (havePermission(context, readPermission) && havePermission(context, writePermission)) { + if (havePermissions(context, requestType)) { permissionsUtils.permissionsListener?.onGranted(permissions) } else { requestPermission(permissionsUtils, permissions) @@ -31,7 +31,10 @@ open class PermissionDelegate23 : com.fluttercandies.photo_manager.permission.Pe } override fun havePermissions(context: Context, requestType: Int): Boolean { - return havePermission(context, readPermission) && havePermission(context, writePermission) + val requireWritePermission = havePermissionInManifest(context, writePermission) + val validWritePermission = + !requireWritePermission || havePermission(context, writePermission) + return havePermission(context, readPermission) && validWritePermission } override fun haveMediaLocation(context: Context): Boolean { @@ -43,10 +46,10 @@ open class PermissionDelegate23 : com.fluttercandies.photo_manager.permission.Pe requestType: Int, mediaLocation: Boolean ): PermissionResult { - if (havePermissions(context, readPermission, writePermission)) { - return PermissionResult.Authorized + return if (havePermissions(context, requestType)) { + PermissionResult.Authorized } else { - return PermissionResult.Denied + PermissionResult.Denied } } -} \ No newline at end of file +} diff --git a/android/src/main/kotlin/com/fluttercandies/photo_manager/permission/impl/PermissionDelegate33.kt b/android/src/main/kotlin/com/fluttercandies/photo_manager/permission/impl/PermissionDelegate33.kt index af8acdb0..79b4fc8f 100644 --- a/android/src/main/kotlin/com/fluttercandies/photo_manager/permission/impl/PermissionDelegate33.kt +++ b/android/src/main/kotlin/com/fluttercandies/photo_manager/permission/impl/PermissionDelegate33.kt @@ -92,4 +92,4 @@ class PermissionDelegate33 : PermissionDelegate() { PermissionResult.Denied } } -} \ No newline at end of file +} diff --git a/android/src/main/kotlin/com/fluttercandies/photo_manager/permission/impl/PermissionDelegate34.kt b/android/src/main/kotlin/com/fluttercandies/photo_manager/permission/impl/PermissionDelegate34.kt index af3b9e98..3d8c537d 100644 --- a/android/src/main/kotlin/com/fluttercandies/photo_manager/permission/impl/PermissionDelegate34.kt +++ b/android/src/main/kotlin/com/fluttercandies/photo_manager/permission/impl/PermissionDelegate34.kt @@ -264,4 +264,4 @@ class PermissionDelegate34 : PermissionDelegate() { return result } -} \ No newline at end of file +} diff --git a/example/android/app/src/main/AndroidManifest.xml b/example/android/app/src/main/AndroidManifest.xml index 9d593f09..3d112a6a 100644 --- a/example/android/app/src/main/AndroidManifest.xml +++ b/example/android/app/src/main/AndroidManifest.xml @@ -1,14 +1,15 @@ - + + ( - future: item.assetCountAsync, - builder: (_, AsyncSnapshot data) { - if (data.hasData) { - return Text('count : ${data.data}'); - } - return const SizedBox.shrink(); - }, - ), - trailing: _buildSubButton(item), - ), + return InkWell( onTap: () async { if (item.albumType == 2) { showToast("The folder can't get asset"); @@ -108,6 +95,19 @@ class GalleryItemWidget extends StatelessWidget { // final asset = list[i]; // } // }, + child: ListTile( + title: Text(item.name), + subtitle: FutureBuilder( + future: item.assetCountAsync, + builder: (_, AsyncSnapshot data) { + if (data.hasData) { + return Text('count : ${data.data}'); + } + return const SizedBox.shrink(); + }, + ), + trailing: _buildSubButton(item), + ), ); } diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 15e661bf..6020824f 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -1,6 +1,6 @@ name: photo_manager_example description: Demonstrates how to use the photo_manager plugin. -version: 3.2.1+28 +version: 3.2.2+29 publish_to: none environment: diff --git a/example_ohos/pubspec.yaml b/example_ohos/pubspec.yaml index 2949fdf8..49126ceb 100644 --- a/example_ohos/pubspec.yaml +++ b/example_ohos/pubspec.yaml @@ -1,6 +1,6 @@ name: photo_manager_example_ohos description: Demonstrates how to use the photo_manager plugin. -version: 3.1.0+26 +version: 3.2.2+29 publish_to: none environment: diff --git a/pubspec.yaml b/pubspec.yaml index 8a1ce626..3a36544d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: photo_manager description: A Flutter plugin that provides album assets abstraction management APIs on Android, iOS, macOS, and OpenHarmony. repository: https://github.com/fluttercandies/flutter_photo_manager -version: 3.2.1 +version: 3.2.2 environment: sdk: ">=2.13.0 <4.0.0"