Baseflow / Baseflow/flutter-permission-handler

Add a method to get All Defined Permissions of the AndroidManifest.xml file.

Open
#1,495 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Dart
Stars
2.2k
Forks
970
Avg merge
14h 22m
Merged PRs (30d)
2

Description

### Is there already an issue requesting this feature?

- [x] I have searched the [existing issues](https://github.com/baseflow/flutter-permission-handler/issues).

### Please select affected platform(s)

- [x] Android
- [ ] iOS
- [ ] Windows

### Use case

Currently Permission.values returns all permissions, if we had a getDefinedPermissions() that would return only the permissions i put on androidManifest.xml i coud loop the returned list to see if there is a permission that is not granted, and if there is i could just call list.request();

### Proposal

i once made something like this on native android
```Java
if (PermissionCheck.needToAsk(this)) {
PermissionCheck.ask(this);
return;
}

public class PermissionCheck {

private PermissionCheck() {

}

public static boolean needToAsk(Context context) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
return false;
}
try {
PackageInfo packageInfo;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.PackageInfoFlags.of(PackageManager.GET_PERMISSIONS));
} else {
packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_PERMISSIONS);
}
String[] permissions = packageInfo.requestedPermissions;

for (String permission : permissions) {
if (isNotGranted(context, permission)) {
return true;
}
}

} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return false;
}

private static boolean isNotGranted(Context context, String permission) {
if (Build.VERSION.SDK_INT < 31 && (permission.contains("BLUETOOTH_SCAN") || permission.contains("BLUETOOTH_ADVERTISE") || permission.contains("BLUETOOTH_CONNECT"))) {
return false;
}
return ContextCompat.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED;
}

public static void ask(Activity context) {
try {
PackageInfo packageInfo;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.PackageInfoFlags.of(PackageManager.GET_PERMISSIONS));
} else {
packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_PERMISSIONS);
}
String[] permissions = packageInfo.requestedPermissions;
List list = new ArrayList<>();
for (String permission : permissions) {
if (isNotGranted(context, permission)) {
list.add(permission);
}
}
if (list.isEmpty()) {
return;
}
String[] array = list.toArray(new String[0]);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
ActivityCompat.requestPermissions(context, array, 0);
}

} catch (PackageManager.NameNotFoundException e) {
MetodosEstaticos.toastException(e, context);
}
}
}
```

But i guess a getDefinedPermissions would be enough.

### Specific requirements or considerations

_No response_

### Additional information or context

_No response_

Contributor guide

Open the contributing guide

Research direction

Start at the Permission.values API and trace the Android plugin path that reads AndroidManifest.xml; review how the existing permission list is exposed to Dart. Done means an Android-only getDefinedPermissions() result contains only manifest-declared permissions and can be iterated for subsequent permission checks.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, dart
Domain
mobile, security
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.