android_permissions_manager 0.0.4

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

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 Flutter:


$ flutter packages get

Alternatively, your editor might support 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

Analysis

We analyzed this package on Jun 19, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0-dev.63.0
  • pana: 0.11.3
  • Flutter: 0.5.4

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
0 / 100
Health:
Code health derived from static analysis. [more]
99 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100 / 100
Overall score:
Weighted score of the above. [more]
50
Learn more about scoring.

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Suggestions

  • The description is too short.

    Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

  • Fix analysis and formatting issues.

    Analysis or formatting checks reported 1 hint.

    Run flutter format to format lib/android_permissions_manager.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.19.0 <2.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.6 1.14.10
meta 1.1.5
sky_engine 0.0.99
typed_data 1.1.5
vector_math 2.0.6 2.0.7