[mobile][photos] Explicitly ask for media location (#1261)

## Description

On bumping up photo_manager version, it introduced a breaking change
where we need to explicitly ask for ACCESS_MEDIA_LOCATION permission.

## Tests

Tested on android 13 and 14 devices.
This commit is contained in:
Ashil 2024-03-30 16:48:15 +05:30 committed by GitHub
parent 6974672f8c
commit 7950f1ec26
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 32 additions and 4 deletions

View file

@ -61,7 +61,14 @@ class LocalSyncService {
return;
}
if (Platform.isAndroid && AppLifecycleService.instance.isForeground) {
final permissionState = await PhotoManager.requestPermissionExtend();
final permissionState = await PhotoManager.requestPermissionExtend(
requestOption: const PermissionRequestOption(
androidPermission: AndroidPermission(
type: RequestType.common,
mediaLocation: true,
),
),
);
if (permissionState != PermissionState.authorized) {
_logger.severe(
"sync requested with invalid permission",

View file

@ -48,7 +48,14 @@ class _HomeHeaderWidgetState extends State<HomeHeaderWidget> {
onTap: () async {
try {
final PermissionState state =
await PhotoManager.requestPermissionExtend();
await PhotoManager.requestPermissionExtend(
requestOption: const PermissionRequestOption(
androidPermission: AndroidPermission(
type: RequestType.common,
mediaLocation: true,
),
),
);
await LocalSyncService.instance.onUpdatePermission(state);
} on Exception catch (e) {
Logger("HomeHeaderWidget").severe(

View file

@ -91,7 +91,14 @@ class GrantPermissionsWidget extends StatelessWidget {
key: const ValueKey("grantPermissionButton"),
child: Text(S.of(context).grantPermission),
onPressed: () async {
final state = await PhotoManager.requestPermissionExtend();
final state = await PhotoManager.requestPermissionExtend(
requestOption: const PermissionRequestOption(
androidPermission: AndroidPermission(
type: RequestType.common,
mediaLocation: true,
),
),
);
if (state == PermissionState.authorized ||
state == PermissionState.limited) {
await SyncService.instance.onPermissionGranted(state);

View file

@ -203,7 +203,14 @@ class AddPhotosPhotoWidget extends StatelessWidget {
}
} catch (e) {
if (e is StateError) {
final PermissionState ps = await PhotoManager.requestPermissionExtend();
final PermissionState ps = await PhotoManager.requestPermissionExtend(
requestOption: const PermissionRequestOption(
androidPermission: AndroidPermission(
type: RequestType.common,
mediaLocation: true,
),
),
);
if (ps != PermissionState.authorized && ps != PermissionState.limited) {
await showChoiceDialog(
context,