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

Popular posts from this blog

2. FreeCodeCamp - Dynamic Programming - Learn to Solve Algorithmic Problems & Coding Challenges

20. Data Analytics - Analyze Data to Answer Questions - Week 1

3. Algorithms - Selection Sort