android_permissions_manager 0.0.4

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 14

android_permissions_manager

Plugin to manage permissions on Android.

Based heavily on flutter_simple_permissions.

Getting Started

Add the dependency to your pubspec.yaml:

dependencies:
  android_permissoins_manager: any

For help getting started with Flutter, view our online documentation.

Usage Example

Import the package:

import 'package:android_permissions_manager/android_permissions_manager.dart'

Requesting a Permission

requestPermission() will open a dialog for the user to allow or deny the permission you are asking for.

PermissionResult result = await AndroidPermissionsManager.requestPermission(PermissionType.CAMERA);

switch(result) {
  case PermissionResult.granted:
    setState(() {
      _granted = true;
    });
    break;
  case PermissionResult.denied:
    setState(() {
      _granted = false;
    });
    break;
  case PermissionResult.showRationale:
    // showRationale means you should show the user why you need this permission
    Scaffold.of(context).showSnackBar(SnackBar(
      content: Text("We need the camera to show an image preview"),
    ));
    setState(() {
      _granted = false;
    });
    break;
}

Checking a Permission

checkPermission() will check if a user has previously granted a permission.

PermissionResult result = await AndroidPermissionsManager.checkPermission(PermissionType.CAMERA);

switch(result) {
  case PermissionResult.granted:
    setState(() {
      _granted = true;
    });
    break;
  case PermissionResult.denied:
    setState(() {
      _granted = false;
    });
    break;
  case PermissionResult.showRationale:
    // showRationale should be treated as denied when checking permissions
    setState(() {
      _granted = false;
    });
    break;
}

Opening Settings

Sometimes you will have top open the app settings (i.e. if a user has accidentally permanently denied a permision that you need)

// Always returns true instantly
bool result = await AndroidPermissionsManager.openSettings();

[0.0.1] - TODO: Add release date.

  • TODO: Describe initial release.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:android_permissions_manager/android_permissions_manager.dart';
import 'package:flutter/foundation.dart';
import 'package:android_permissions_manager_example/permissionsView.dart';

void main() => runApp(new MyApp());



class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {
  List<PermissionsButton> permissions = [
    PermissionsButton("READ_CALENDAR"),
    PermissionsButton("WRITE_CALENDAR"),
    PermissionsButton("CAMERA"),
    PermissionsButton("READ_CONTACTS"),
    PermissionsButton("WRITE_CONTACTS"),
    PermissionsButton("GET_ACCOUNTS"),
    PermissionsButton("ACCESS_FINE_LOCATION"),
    PermissionsButton("ACCESS_COARSE_LOCATION"),
    PermissionsButton("RECORD_AUDIO"),
    PermissionsButton("READ_PHONE_STATE"),
    PermissionsButton("READ_PHONE_NUMBERS"),
    PermissionsButton("CALL_PHONE"),
    PermissionsButton("ANSWER_PHONE_CALLS"),
    PermissionsButton("READ_CALL_LOG"),
    PermissionsButton("WRITE_CALL_LOG"),
    PermissionsButton("ADD_VOICEMAIL"),
    PermissionsButton("USE_SIP"),
    PermissionsButton("PROCESS_OUTGOING_CALLS"),
    PermissionsButton("BODY_SENSORS"),
    PermissionsButton("SEND_SMS"),
    PermissionsButton("RECEIVE_SMS"),
    PermissionsButton("READ_SMS"),
    PermissionsButton("RECEIVE_WAP_PUSH"),
    PermissionsButton("RECEIVE_MMS"),
    PermissionsButton("READ_EXTERNAL_STORAGE"),
    PermissionsButton("WRITE_EXTERNAL_STORAGE"),
  ];

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        appBar: new AppBar(
          title: new Text('Plugin example app'),
          actions: <Widget>[
            IconButton(
              icon: Icon(Icons.settings),
              onPressed: () async {
                bool result = await AndroidPermissionsManager.openSettings();
                debugPrint(result.toString());
              }
            ),
            IconButton(
              icon: Icon(Icons.sms),
              onPressed: () async {
                List<PermissionResult> results = await AndroidPermissionsManager.requestPermissions(<PermissionType>[
                  PermissionType.SEND_SMS,
                  PermissionType.READ_SMS,
                ]);
                debugPrint(results.toString());
              },
            )
          ],
        ),
        body: Center(
          child: PermissionsGridView(permissions),
        )
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  android_permissions_manager: ^0.0.4

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:android_permissions_manager/android_permissions_manager.dart';
  
Version Uploaded Documentation Archive
0.0.4 Jun 13, 2018 Go to the documentation of android_permissions_manager 0.0.4 Download android_permissions_manager 0.0.4 archive
0.0.3 Jun 13, 2018 Go to the documentation of android_permissions_manager 0.0.3 Download android_permissions_manager 0.0.3 archive
0.0.2 Jun 8, 2018 Go to the documentation of android_permissions_manager 0.0.2 Download android_permissions_manager 0.0.2 archive
0.0.1 Jun 8, 2018 Go to the documentation of android_permissions_manager 0.0.1 Download android_permissions_manager 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
29
Health:
Code health derived from static analysis. [more]
--
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
--
Overall:
Weighted score of the above. [more]
14
Learn more about scoring.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Analysis issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see https://www.dartlang.org/dart-2#migration.

Maintenance issues and suggestions

Running dartdoc failed. (-10 points)

Make sure dartdoc runs without any issues.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.19.0 <2.0.0