Skip to content

Commit

Permalink
šŸ› Do not require WRITE_EXTERNAL_STORAGE if not declared in the maniā€¦
Browse files Browse the repository at this point in the history
ā€¦fest with Android 29- (#1158)

Signed-off-by: Caijinglong <[email protected]>
Co-authored-by: Caijinglong <[email protected]>
  • Loading branch information
AlexV525 and CaiJingLong authored Jul 15, 2024
1 parent fe4fa9c commit 67f9ba9
Show file tree
Hide file tree
Showing 15 changed files with 45 additions and 44 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

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

<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="32"/>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ object DBUtils : IDBUtils {
val list = ArrayList<AssetPathEntity>()
val args = ArrayList<String>()
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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -174,5 +173,4 @@ abstract class PermissionDelegate {
requestType: Int,
mediaLocation: Boolean
): PermissionResult

}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.fluttercandies.photo_manager.permission

interface PermissionsListener {

fun onGranted(needPermissions: MutableList<String>)

fun onDenied(
deniedPermissions: MutableList<String>,
grantedPermissions: MutableList<String>,
needPermissions: MutableList<String>
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,6 @@ class PermissionsUtils {
if (needToRequestPermissionsList.isNotEmpty()) needToRequestPermissionsList.clear()
}

/**
*
*/

/**
* č·³č½¬åˆ°åŗ”ē”Øēš„č®¾ē½®ē•Œé¢
*
Expand Down Expand Up @@ -206,5 +202,4 @@ class PermissionsUtils {
fun getAuthValue(requestType: Int, mediaLocation: Boolean): PermissionResult {
return delegate.getAuthValue(context!!, requestType, mediaLocation)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ class PermissionDelegate19 : com.fluttercandies.photo_manager.permission.Permiss
): PermissionResult {
return PermissionResult.Authorized
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,18 @@ 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)
}
}

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 {
Expand All @@ -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
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,4 @@ class PermissionDelegate33 : PermissionDelegate() {
PermissionResult.Denied
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -264,4 +264,4 @@ class PermissionDelegate34 : PermissionDelegate() {

return result
}
}
}
7 changes: 4 additions & 3 deletions example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="28"/>

<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
<uses-permission android:name="android.permission.READ_MEDIA_VISUAL_USER_SELECTED" />

<!-- Optional permissions -->
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="28"/>
<uses-permission android:name="android.permission.ACCESS_MEDIA_LOCATION" />

<application
Expand Down
28 changes: 14 additions & 14 deletions example/lib/widget/gallery_item_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,7 @@ class GalleryItemWidget extends StatelessWidget {

Widget buildGalleryItemWidget(AssetPathEntity item, BuildContext context) {
final navigator = Navigator.of(context);
return GestureDetector(
child: ListTile(
title: Text(item.name),
subtitle: FutureBuilder<int>(
future: item.assetCountAsync,
builder: (_, AsyncSnapshot<int> 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");
Expand Down Expand Up @@ -108,6 +95,19 @@ class GalleryItemWidget extends StatelessWidget {
// final asset = list[i];
// }
// },
child: ListTile(
title: Text(item.name),
subtitle: FutureBuilder<int>(
future: item.assetCountAsync,
builder: (_, AsyncSnapshot<int> data) {
if (data.hasData) {
return Text('count : ${data.data}');
}
return const SizedBox.shrink();
},
),
trailing: _buildSubButton(item),
),
);
}

Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
2 changes: 1 addition & 1 deletion example_ohos/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down

0 comments on commit 67f9ba9

Please sign in to comment.