GithubHelp home page GithubHelp logo

bryksin / unityandroidpermissions Goto Github PK

View Code? Open in Web Editor NEW

This project forked from over17/unityandroidpermissions

0.0 1.0 0.0 26 KB

Unity Android Runtime Permissions for Android Marshmallow

License: MIT License

C# 59.93% Java 40.07%

unityandroidpermissions's Introduction

UnityAndroidPermissions

Starting with Android Marshmallow (Android 6), Google introduced Runtime permissions system where the user is asked to grant a permission in runtime rather than doing that during installation of the app. However, Unity for Android is not supporting it out of the box because:

  • the corresponding Android API requires an Activity, when Unity can run without it. All non-Activity Unity applications are not supported for that reason
  • the plugins may add a dangerous permission and not have the code to handle it correctly, thus causing the whole app to crash This is the reason why Unity prompts the user for all the permissions on startup. This behavior is the safest and most compatible.

However, Google requires the runtime permission system to be implemented to get featured on Google Play. To let the user implement it (and take the responsibility), the Unity's dialog on startup can be suppressed by adding "unityplayer.SkipPermissionsDialog"="true" metadata tag to application or activity section of the Android Manifest.

This plugin is one of the Android runtime permissions for Unity implementations. It provides the API to check the status of a permission, request a set of permissions and get a callback with the result.

API

AndroidPermissionsManager is the class which provides you the following methods:

  • bool IsPermissionGranted(string permissionName) to check the status of a permission
  • void RequestPermission(string[] permissionNames, AndroidPermissionCallback callback) to query for an array of permissions. Pass AndroidPermissionCallback object or an object of derived class with your own callback implementation. void AndroidPermissionCallback.OnPermissionGranted(string permissionName) is called when a permission is granted, void OnPermissionDenied(string permissionName) - when a permission is denied.

Usage

  1. Should work with Unity 5.3+. Please report an issue if it does not for you
  2. Add the plugin to your project. You need the AAR and the C# script (Assets/Plugins/Android/unityandroidpermissions.aar and Assets/Scripts/AndroidPermissionsManager.cs)
  3. Use the C# API in your scripts to check the permission status and request it if necessary, right before you actually need this permission
  4. Enjoy

For more details please refer to Assets/Scripts/AndroidPermissionsManager.cs script

How to Build

Use Android Studio to build the AAR from the source in src/ directory.

See Also

Please refer to Google documentation for more details: https://developer.android.com/training/permissions/requesting.html

unityandroidpermissions's People

Contributors

bryksin avatar over17 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.