-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix aos storage permission not be requested when api above 33 (#168)
* chore: add image/video, music/audio permission into android manifest * feat: seperate permission request content by aos api 33 * chore: add device into package * refactor: migrate file page to null safety, with pieces of UI improvements such as color * refactor: null-safety migrations
- Loading branch information
1 parent
327f239
commit 510d499
Showing
12 changed files
with
296 additions
and
266 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,43 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:device_info_plus/device_info_plus.dart'; | ||
import 'package:permission_handler/permission_handler.dart'; | ||
|
||
class PermissionsUtil { | ||
/// Checks if the APP can access to the file sys on the current device. | ||
/// | ||
/// If it can not access to, an External Storage (id = 15) warning will occurred. | ||
/// So please check if the androidManifest.xml has the following permission declarations: | ||
/// - uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" | ||
/// - uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" | ||
static Future<bool> checkHasAosStoragePermission() async { | ||
// On iOS, the permission is managed by xcode project config. | ||
if (Platform.isIOS) return true; | ||
assert(Platform.isAndroid, 'The platform most be either aos or ios.'); | ||
|
||
return await Permission.storage.request().isGranted; | ||
final deviceInfoPlugin = DeviceInfoPlugin(); | ||
final androidSdkVersion = (await deviceInfoPlugin.androidInfo).version.sdkInt; | ||
final requiredPermissions = <Permission>[]; | ||
|
||
// About the new `Granular media permissions` policy: | ||
// Above Android API 33, the permission of storage is split into image/videos and music/audio. | ||
// Which means we can't request the `READ_EXTERNAL_STORAGE`. | ||
// And since the `permission_handler v10.2.0` still not support the new policy, | ||
// we have to request the separate permissions. | ||
// Please refer to https://developer.android.com/about/versions/13/behavior-changes-13#granular-media-permissions | ||
if (androidSdkVersion >= 33) { | ||
requiredPermissions.addAll([ | ||
Permission.videos, | ||
Permission.audio, | ||
]); | ||
} else { | ||
requiredPermissions.addAll([ | ||
Permission.storage, | ||
]); | ||
} | ||
|
||
await requiredPermissions.request(); | ||
final determineResult = await Future.wait(requiredPermissions.map((permission) => permission.isGranted)); | ||
|
||
// Since the requiredPermissions is a list, user can choose to grant or deny any of them. | ||
// So we have to check if any of them (instead of `every`) is granted. | ||
// This depends on all the permissions in the list are able to make the App | ||
// access the device's storage once they've been granted. | ||
return determineResult.any((permission) => permission); | ||
} | ||
} |
Oops, something went wrong.