23. Flutter - Android Studio Request Permissions
To request permissions edit the AndroidManifest.xml file.
1. Android>app>main>AndroidManifest.xml
2. Add line under manifest tree pertaining to specific permissions the app will use/request:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Use permission handler package for flutter:
1. Add "permission_handler: ^8.3.0" under dependencies in pubspec.yaml file
2. Import into a dart file:
import 'package:permission_handler/permission_handler.dart';
3. Create new function to request permission and/or check status of permission and handle it:
permission() async {
var status = await Permission.storage.status;
if (status.isDenied) {
// You can request multiple permissions at once.
Map<Permission, PermissionStatus> statuses = await [
Permission.storage,
].request();
print(statuses[Permission.storage]); // it should print PermissionStatus.granted
}
}
Comments
Post a Comment