From 0de4345db88be76b359271235274fad42724ad23 Mon Sep 17 00:00:00 2001
From: Ludvig Eriksson <11162271+LulleBulle@users.noreply.github.com>
Date: Mon, 5 Aug 2024 09:09:34 +0200
Subject: [PATCH] added partial media permission to android (#1347)
* added partial media permission to android and bumped compileSDK to 34. Also set android project to use local interface
* updated unit test with total permissions count + reset pubspec to not use local path
* baked the partial permission into original photo
* removed the partial permission as its baked into photos now
* added new limited to videos as well
* fixed format
* Versioning + reset platform_interface
---
permission_handler_android/CHANGELOG.md | 4 ++++
permission_handler_android/android/build.gradle | 2 +-
.../permissionhandler/PermissionConstants.java | 2 +-
.../permissionhandler/PermissionManager.java | 13 ++++++++++++-
.../example/android/app/build.gradle | 4 ++--
.../android/app/src/main/AndroidManifest.xml | 1 +
permission_handler_android/pubspec.yaml | 2 +-
7 files changed, 22 insertions(+), 6 deletions(-)
diff --git a/permission_handler_android/CHANGELOG.md b/permission_handler_android/CHANGELOG.md
index 04ab8b1d3..bdf0a9a5c 100644
--- a/permission_handler_android/CHANGELOG.md
+++ b/permission_handler_android/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 12.0.8
+
+* Added support for limited photo and video permission on Android.
+
## 12.0.7
* Removes additional Android v1 embedding class reference.
diff --git a/permission_handler_android/android/build.gradle b/permission_handler_android/android/build.gradle
index 315b0761f..73622f51d 100644
--- a/permission_handler_android/android/build.gradle
+++ b/permission_handler_android/android/build.gradle
@@ -26,7 +26,7 @@ android {
if (project.android.hasProperty("namespace")) {
namespace 'com.baseflow.permissionhandler'
}
- compileSdk 33
+ compileSdk 34
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
diff --git a/permission_handler_android/android/src/main/java/com/baseflow/permissionhandler/PermissionConstants.java b/permission_handler_android/android/src/main/java/com/baseflow/permissionhandler/PermissionConstants.java
index 841595e6a..0262db176 100644
--- a/permission_handler_android/android/src/main/java/com/baseflow/permissionhandler/PermissionConstants.java
+++ b/permission_handler_android/android/src/main/java/com/baseflow/permissionhandler/PermissionConstants.java
@@ -100,7 +100,7 @@ final class PermissionConstants {
PERMISSION_GROUP_SCHEDULE_EXACT_ALARM,
PERMISSION_GROUP_CALENDAR_WRITE_ONLY,
PERMISSION_GROUP_CALENDAR_FULL_ACCESS,
- PERMISSION_GROUP_ASSISTANT
+ PERMISSION_GROUP_ASSISTANT,
})
@interface PermissionGroup {
}
diff --git a/permission_handler_android/android/src/main/java/com/baseflow/permissionhandler/PermissionManager.java b/permission_handler_android/android/src/main/java/com/baseflow/permissionhandler/PermissionManager.java
index ad420830d..4e08a04f7 100644
--- a/permission_handler_android/android/src/main/java/com/baseflow/permissionhandler/PermissionManager.java
+++ b/permission_handler_android/android/src/main/java/com/baseflow/permissionhandler/PermissionManager.java
@@ -537,7 +537,18 @@ private int determinePermissionStatus(final @PermissionConstants.PermissionGroup
} else {
permissionStatuses.add(PermissionConstants.PERMISSION_STATUS_GRANTED);
}
- } else {
+ } else if (permission == PermissionConstants.PERMISSION_GROUP_PHOTOS || permission == PermissionConstants.PERMISSION_GROUP_VIDEOS){
+ final int permissionStatusLimited = ContextCompat.checkSelfPermission(context, Manifest.permission.READ_MEDIA_VISUAL_USER_SELECTED);
+ final int permissionStatus = ContextCompat.checkSelfPermission(context, name);
+ if (permissionStatusLimited == PackageManager.PERMISSION_GRANTED){
+ permissionStatuses.add(PermissionConstants.PERMISSION_STATUS_LIMITED);
+ }
+ else{
+ if (permissionStatus != PackageManager.PERMISSION_GRANTED) {
+ permissionStatuses.add(PermissionUtils.determineDeniedVariant(activity, name));
+ }
+ }
+ }else {
final int permissionStatus = ContextCompat.checkSelfPermission(context, name);
if (permissionStatus != PackageManager.PERMISSION_GRANTED) {
permissionStatuses.add(PermissionUtils.determineDeniedVariant(activity, name));
diff --git a/permission_handler_android/example/android/app/build.gradle b/permission_handler_android/example/android/app/build.gradle
index 1ed3dcef4..93c36181d 100644
--- a/permission_handler_android/example/android/app/build.gradle
+++ b/permission_handler_android/example/android/app/build.gradle
@@ -26,13 +26,13 @@ apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
namespace 'com.baseflow.permissionhandler.example'
- compileSdk 33
+ compileSdk 34
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.baseflow.permissionhandler.example"
minSdkVersion flutter.minSdkVersion
- targetSdkVersion flutter.targetSdkVersion
+ targetSdkVersion 34
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
diff --git a/permission_handler_android/example/android/app/src/main/AndroidManifest.xml b/permission_handler_android/example/android/app/src/main/AndroidManifest.xml
index 6f7c32fd4..c9457c995 100644
--- a/permission_handler_android/example/android/app/src/main/AndroidManifest.xml
+++ b/permission_handler_android/example/android/app/src/main/AndroidManifest.xml
@@ -26,6 +26,7 @@
+
diff --git a/permission_handler_android/pubspec.yaml b/permission_handler_android/pubspec.yaml
index 51b3acba3..c05ef60a8 100644
--- a/permission_handler_android/pubspec.yaml
+++ b/permission_handler_android/pubspec.yaml
@@ -1,7 +1,7 @@
name: permission_handler_android
description: Permission plugin for Flutter. This plugin provides the Android API to request and check permissions.
homepage: https://github.com/baseflow/flutter-permission-handler
-version: 12.0.7
+version: 12.0.8
environment:
sdk: ">=2.15.0 <4.0.0"