grant method

Future<void> grant(
  1. String packageName,
  2. String permission, {
  3. String? user,
  4. bool debug = false,
})

grant the specified permission to the package with the given packageName.

If user is provided, the permission is granted to the specified user.

Throws an exception if the package manager command fails.

Example:

await pm.grant('com.example.app', 'android.permission.CAMERA');

Implementation

Future<void> grant(String packageName, String permission, {String? user, bool debug = false}) async {
  final args = ['pm', 'grant'];

  if (user != null) {
    args.addAll(['--user', user]);
  }

  args.addAll([packageName, permission]);
  await _shell.exec(args, debug: debug);
}