Search Unity

[Open Source] AndroidRuntimePermissions - manage runtime permissions "synchronously" on Android M+

Discussion in 'Assets and Asset Store' started by yasirkula, Apr 28, 2018.

  1. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    You should create the Android folder inside Plugins if it doesn't exist, yes.

    Try building the app to your device. Unity Remote may not work because with Remote, the game actually runs on PC and is streamed to the mobile device.
     
  2. rutkoski

    rutkoski

    Joined:
    Jan 9, 2015
    Posts:
    5
    Hi, does the plugin work with ARM64 and il2cpp? Thanks.
     
  3. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Haven't tested it but I can't think of any reasons for it not to work. If you are using ProGuard, you will have to add the following line to its filters:

    -keep class com.yasirkula.unity.* { *; }
     
  4. damithw

    damithw

    Joined:
    May 24, 2019
    Posts:
    1
    hi, Thank you so much for the plugin.

    But there is a problem with Unity 2019. Also I have enabled ARM64 and il2cpp.

    I am getting following exception. This is logcart logs.


    Is there anything that I have done wrong or the plugin does not support unity 2019 ?
     
  5. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    If your project uses ProGuard, try adding the following line to ProGuard filters:
    -keep class com.yasirkula.unity.* { *; }


    Be aware that some users have reported that on Unity 2019, their app froze after requesting a permission. I wasn't able to resolve that issue yet.
     
  6. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,187
    Just came here to report a similar issue. So, we're using your plugin to request camera permission. We discovered that after the user grants the permission, the camera comes up but it appears to be frozen. However, we discovered that if you put the app in the background and then bring it back, the camera is working fine. My coworker and I were discussing it and it almost appeared that for some reason after the permission was granted, Unity didn't get focus back completely. No errors were thrown in logcat and our coroutine that runs didn't run.

    Hope this bit of information helps.
     
  7. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,187
    Also to add

    Vuforia seemed to have the same issue with the camera

     
    yasirkula likes this.
  8. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    This issue affected a number of my native plugins but I might have found a solution to this. Basically, I'm trying to resume the Unity activity manually after asking the permission. Can you try importing the attached unitypackage to your project and see if this fix resolves the issue?

    P.S. If the permission dialog won't show up, try uninstalling the app first. This will reset the cached Denied-permissions.
     

    Attached Files:

    Last edited: Jul 17, 2019
  9. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,187
    Tried it out. There did seem to be a really quick pause after granting the app camera permission, but it did resume and seem to work normally. Tested on 3 devices with various OS versions.

    Thanks!
     
    yasirkula likes this.
  10. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Glad to hear it! I'm waiting for response from a few other users, as well. If none of them report any issues, then I'll update all my plugins that depend on Android runtime permissions.
     
  11. yein_buck

    yein_buck

    Joined:
    Jul 8, 2019
    Posts:
    1
    It also worked for me, thanks for the plug-in!
     
    yasirkula likes this.
  12. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Thank you all for your feedback. Updated the plugin on GitHub. Asset Store version will probably be updated next week.

    P.S. Asset Store version is now updated.
     
    Last edited: Jul 23, 2019
  13. dizzymediainc

    dizzymediainc

    Joined:
    Apr 6, 2014
    Posts:
    433
    EDIT: Nevermind i got it working :p

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Events;
    5.  
    6. #if PLATFORM_ANDROID
    7. using UnityEngine.Android;
    8. #endif
    9.  
    10. public class PermisCheck2 : MonoBehaviour {
    11.  
    12.     [Header("Debug")]
    13.    
    14.     public bool useDebug;
    15.    
    16.     [Header("User Options")]
    17.    
    18.     public bool autoStart;
    19.    
    20.     public bool checkFor_Permissions;
    21.    
    22.     public float startWait;
    23.    
    24.     [Header("Actions")]
    25.  
    26.     public bool usePermis_Event;
    27.     public UnityEvent permisEvent;
    28.  
    29.     // Start is called before the first frame update
    30.     void Start() {
    31.    
    32.         #if PLATFORM_ANDROID
    33.        
    34.         if(autoStart){
    35.    
    36.             if (!Permission.HasUserAuthorizedPermission(Permission.FineLocation)) {
    37.            
    38.                 StartCoroutine("BuffStart");
    39.            
    40.             } else {
    41.                
    42.                 if(usePermis_Event){
    43.            
    44.                     checkFor_Permissions = false;
    45.                     permisEvent.Invoke();
    46.            
    47.                 }//usePermis_Event
    48.             }
    49.            
    50.         }//autoStart
    51.        
    52.         #endif
    53.     }
    54.    
    55.     private IEnumerator BuffStart(){
    56.        
    57.         yield return new WaitForSeconds(startWait);
    58.        
    59.         checkFor_Permissions = true;
    60.        
    61.     }//checkFor_Permissions
    62.    
    63.  
    64.     void Update(){
    65.    
    66.         #if PLATFORM_ANDROID
    67.        
    68.         if(checkFor_Permissions){
    69.        
    70.               // Requesting WRITE_EXTERNAL_STORAGE and CAMERA permissions simultaneously
    71.               AndroidRuntimePermissions.Permission[] result = AndroidRuntimePermissions.RequestPermissions("android.permission.ACCESS_FINE_LOCATION", "android.permission.WRITE_EXTERNAL_STORAGE");
    72.          
    73.              if(result[0] == AndroidRuntimePermissions.Permission.Granted && result[1] == AndroidRuntimePermissions.Permission.Granted){
    74.            
    75.                 if(useDebug){
    76.            
    77.                     Debug.Log( "We have all the permissions!" );
    78.              
    79.                 }//useDebug
    80.            
    81.                 if(usePermis_Event){
    82.            
    83.                     checkFor_Permissions = false;
    84.                     permisEvent.Invoke();
    85.            
    86.                 }//usePermis_Event
    87.          
    88.             //result
    89.              } else {
    90.          
    91.                 if(useDebug){
    92.            
    93.                      Debug.Log( "Some permission(s) are not granted..." );
    94.            
    95.                 }//useDebug
    96.            
    97.             }//result
    98.        
    99.         }//checkFor_Permissions
    100.        
    101.         #endif
    102.        
    103.     }
    104. }
    105.  
     
    Last edited: Jul 28, 2019
    yasirkula likes this.
  14. Hellfim

    Hellfim

    Joined:
    Sep 11, 2014
    Posts:
    123
    @yasirkula, hello, and thank you for this plugin!
    I'm using Unity 2019.2.1f1 and somewhy plugin doesn't work. When I check permission state (write external) it says it's ShouldAsk. After that I request a permission, game hangs for a second, and I receive a respone (in console) that permission is denied. Without normal system popup or anything.
    Actually I had a same self-written plugin which stopped working, so I decided to check out your version, and it has the same problem. Do you have any idea why is that happening?
     
  15. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Can you verify that the WRITE_EXTERNAL_STORAGE permission exists in the auto-generated AndroidManifest.xml file located at UNITY_PROJECT_PATH/Temp/StagingArea after building your project to Android?
     
  16. Hellfim

    Hellfim

    Joined:
    Sep 11, 2014
    Posts:
    123
    Sorry for the long response. Yep, it's there.
     
  17. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Can you uninstall the app from your device and then reinstall it? If you have added the WRITE_EXTERNAL_STORAGE permission to your app after you've first installed the app to your device, it might happen.
     
  18. Hellfim

    Hellfim

    Joined:
    Sep 11, 2014
    Posts:
    123
    Nope, that's not the case. It was there for several months. Problem only appeared after migrating from 5.6.5 to 2019.2.1f1
     
  19. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    I'd recommend you to try the plugin on an empty 2019.2 project to see the problem is specific to your own project. As much as I'd like to help, I don't really know why the plugin would break when upgrading to 2019.
     
  20. amir0033

    amir0033

    Joined:
    Jul 12, 2015
    Posts:
    1
    Code (JavaScript):
    1.  
    2. // GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAIN
    3.  
    4. buildscript {
    5.     repositories {
    6.         google()
    7.         jcenter()
    8.     }
    9.  
    10.     dependencies {
    11.         classpath 'com.android.tools.build:gradle:3.2.0'
    12. **BUILD_SCRIPT_DEPS**}
    13. }
    14.  
    15. allprojects {
    16.     repositories {
    17.         google()
    18.         jcenter()
    19.         flatDir {
    20.             dirs 'libs'
    21.         }
    22.  
    23.         maven { url 'https://dl.bintray.com/tapsellorg/maven'}
    24.         maven { url  'https://adcolony.bintray.com/AdColony' }
    25.     }
    26. }
    27.  
    28. //Android Resolver Repos Start
    29. allprojects {
    30.     repositories {
    31.         maven {
    32.             url "https://maven.google.com"
    33.         }
    34.         maven {
    35.             url "file:///D:/Unity%20Projects%202018/ProParking%20%20U2019.1.4/Assets/GooglePlayGames/Editor/m2repository" // Assets/GooglePlayGames/Editor/GooglePlayGamesPluginDependencies.xml:11
    36.         }
    37.         mavenLocal()
    38.         jcenter()
    39.         mavenCentral()
    40.     }
    41. }
    42. //Android Resolver Repos End
    43. apply plugin: 'com.android.application'
    44. //apply plugin: 'AndroidRuntimePermissions:Android:RuntimePermissions'
    45.  
    46. **APPLY_PLUGINS**
    47.  
    48. dependencies {
    49.     implementation fileTree(dir: 'libs', include: ['*.jar'])
    50.     implementation 'ir.tapsell.plus:tapsell-plus-sdk-unity:1.0.7'
    51.    //  implementation 'com.yasirkula:unity:1.0.0'
    52.    // compile 'com.android.support:appcompat-v7:23.1.0'
    53.     //for adMob
    54.     implementation 'com.google.android.gms:play-services-ads:17.2.1'
    55.  
    56.     //for unityAds
    57.     implementation 'com.unity3d.ads:unity-ads:3.0.0'
    58.  
    59.     //for chartboost
    60.     implementation 'ir.tapsell.sdk:chartboost-sdk-android:7.3.1'
    61.  
    62.     //for facebook
    63.     implementation 'com.facebook.android:audience-network-sdk:5.3.0'
    64.     implementation 'com.facebook.android:facebook-android-sdk:5.2.0'
    65.  
    66.     //for adcolony
    67.     implementation 'com.adcolony:sdk:3.3.11'
    68.  
    69.     //for applovin
    70.     implementation 'com.applovin:applovin-sdk:9.7.2'
    71.  
    72.     //for vungle
    73.     implementation 'com.vungle:publisher-sdk-android:6.4.11'
    74. // Android Resolver Dependencies Start
    75.     compile 'com.google.games:gpgs-plugin-support:0.9.64' // Assets/GooglePlayGames/Editor/GooglePlayGamesPluginDependencies.xml:11
    76. // Android Resolver Dependencies End
    77. **DEPS**}
    78.  
    79. android {
    80.     compileSdkVersion **APIVERSION**
    81.     buildToolsVersion '**BUILDTOOLS**'
    82.  
    83.     compileOptions {
    84.         sourceCompatibility JavaVersion.VERSION_1_8
    85.         targetCompatibility JavaVersion.VERSION_1_8
    86.     }
    87.  
    88.     defaultConfig {
    89.         minSdkVersion **MINSDKVERSION**
    90.         targetSdkVersion **TARGETSDKVERSION**
    91.         applicationId '**APPLICATIONID**'
    92.         ndk {
    93.             abiFilters **ABIFILTERS**
    94.         }
    95.         versionCode **VERSIONCODE**
    96.         versionName '**VERSIONNAME**'
    97.         multiDexEnabled true
    98.     }
    99.  
    100.     lintOptions {
    101.         abortOnError false
    102.     }
    103.  
    104.     aaptOptions {
    105.         noCompress = ['.unity3d', '.ress', '.resource', '.obb'**STREAMING_ASSETS**]
    106.     }**SIGN**
    107.  
    108.     buildTypes {
    109.         debug {
    110.             // minifyEnabled **MINIFY_DEBUG**
    111.             // useProguard **PROGUARD_DEBUG**
    112.             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt'**USER_PROGUARD**
    113.             jniDebuggable true
    114.         }
    115.         release {
    116.             // minifyEnabled **MINIFY_RELEASE**
    117.             // useProguard **PROGUARD_RELEASE**
    118.             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt'**USER_PROGUARD****SIGNCONFIG**
    119.         }
    120.     }**PACKAGING_OPTIONS****SPLITS**
    121. **BUILT_APK_LOCATION**
    122.     bundle {
    123.         language {
    124.             enableSplit = false
    125.         }
    126.         density {
    127.             enableSplit = false
    128.         }
    129.         abi {
    130.             enableSplit = true
    131.         }
    132.     }
    133. }**SPLITS_VERSION_CODE****REPOSITORIES****SOURCE_BUILD_SETUP**
    134.  

    hi i when use this custom gradle template and run game is show log Denied!!
    but use default unity gradle it worked and show log Granted.
    please show me how can i fix my gradle?
     
  21. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    I'm sorry to hear that. As much as I want to help, I have no experience with custom gradle templates and have no idea where to look at, really. Are there possibly any other error messages in logcat?
     
  22. DevilMayCry6

    DevilMayCry6

    Joined:
    Nov 22, 2016
    Posts:
    1
    Thank you very much,your plugin really solved my problem!!
     
    yasirkula likes this.
  23. stecavalli

    stecavalli

    Joined:
    Oct 26, 2019
    Posts:
    10
    Hi, I have a question. If I want to reset the denied permission to record audio, is it possible to do it in runtime without uninstalling and reinstalling the app (or by clearing the app data and cleaning the cache)?
     
  24. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    stecavalli likes this.
  25. stecavalli

    stecavalli

    Joined:
    Oct 26, 2019
    Posts:
    10
  26. stecavalli

    stecavalli

    Joined:
    Oct 26, 2019
    Posts:
    10
    I added this to the manifest file:
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-feature android:name="android.hardware.camera" />
    <uses-permission android:name="android.permission.FLASHLIGHT" />
    <uses-feature android:name="android.hardware.camera.flash" />
     
  27. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    You can request any necessary permissions with my plugin but my plugin won't help with sending native commands to the flashlight to toggle it. If the example code in the link you've provided doesn't work, check logcat for any meaningful error messages. If it is not related with missing permissions, please create a post for this issue instead of asking me for help.
     
  28. stecavalli

    stecavalli

    Joined:
    Oct 26, 2019
    Posts:
    10
    I did as you suggested and I came to the solution. Thanks
     
  29. GJBooij

    GJBooij

    Joined:
    Jun 18, 2013
    Posts:
    10
    Hello,

    We've been using this plugin in several projects already and it always worked perfectly.
    But since I upgraded my project to 2019.4.0 LTS it gets stuck when
    AndroidRuntimePermissions.Permission[] requestResult = AndroidRuntimePermissions.RequestPermissions("android.permission.ACCESS_FINE_LOCATION");
    is called. Nothing happens, no error logs from Unity nor the Android system. App simply stops responding.

    Sidenote:
    Replacing the logic where we use your plugin with
    Permission.RequestUserPermission("android.permission.ACCESS_FINE_LOCATION");
    does work. We did this to make sure it's the plugin and not something else in our code ;)

    For now we can work with this, but it would be nice if this issue is resolved :)

    Cheers,
    Gert-jan
     
    yasirkula likes this.
  30. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    I couldn't reproduce this issue on a new 2019.4.0f1 project with the same ACCESS_FINE_LOCATION permission. Can you also test the plugin on a new project and if it works smoothly for you, as well, try changing player settings parameters to find the culprit.
     
  31. Paulo_Ferrato

    Paulo_Ferrato

    Joined:
    Nov 26, 2018
    Posts:
    4
    Hey Man! Noob here! Still working for Unity 2020?
     
  32. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    I haven't tried it on Unity 2020 but I'd guess that it would work, yes.
     
  33. StarArcher

    StarArcher

    Joined:
    May 23, 2020
    Posts:
    12
    It's now 20 months later.... and this solved my perplexing problem. THANK YOU!!!
     
    yasirkula likes this.
  34. Sashimiii

    Sashimiii

    Joined:
    Sep 26, 2017
    Posts:
    15
    Hi Yasirkula,

    Question here. I've tried implementing your pedometer for an Android with a version 10. However, it seems like from target SDK 29 and higher it doesn't work. Therefore I've downloaded this asset from you to trigger a permission box to ask the user for permission.

    But somehow the plugin doesn't trigger a permission box and therefore will always return false.

    I've included
    Code (CSharp):
    1.     <uses-permission android:name="android.permission.ACTIVITY_RECOGNITION"/>
    In the AndroidManifest file, however it doesn't seem to help with anything.

    This is my AndroidManifest.xml:
    Code (CSharp):
    1. <?xml version="1.0" encoding="utf-8"?>
    2.  
    3. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    4.           xmlns:tools="http://schemas.android.com/tools"
    5.           package="com.deadmosquitogames.androidgoodiesdemo.assetstore"
    6.           android:versionName="1.0" android:versionCode="1" android:installLocation="preferExternal">
    7.     <supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true"
    8.                       android:xlargeScreens="true" android:anyDensity="true"/>
    9.     <uses-feature android:glEsVersion="0x00020000"/>
    10.     <supports-gl-texture android:name="GL_OES_compressed_ETC1_RGB8_texture"/>
    11.     <application android:theme="@style/UnityThemeSelector" android:icon="@drawable/app_icon"
    12.                  android:label="@string/app_name" android:debuggable="false" android:isGame="true">
    13.         <activity android:name="com.unity3d.player.UnityPlayerActivity" android:label="@string/app_name"
    14.                   android:screenOrientation="fullSensor" android:launchMode="singleTask"
    15.                   android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale">
    16.             <intent-filter>
    17.                 <action android:name="android.intent.action.MAIN"/>
    18.                 <category android:name="android.intent.category.LAUNCHER"/>
    19.                 <category android:name="android.intent.category.LEANBACK_LAUNCHER"/>
    20.             </intent-filter>
    21.             <meta-data android:name="unityplayer.UnityActivity" android:value="true"/>
    22.         </activity>
    23.      
    24.         <!-- Unity requests all the runtime permissions when you application starts, all in a row. Uncomment these lines to prevent this from happening-->
    25.         <!--<meta-data-->
    26.                 <!--android:name="unityplayer.SkipPermissionsDialog"-->
    27.                 <!--android:value="true"/>-->
    28.     </application>
    29.  
    30.     <!-- PERMISSIONS -->
    31.     <uses-permission android:name="android.permission.INTERNET"/>
    32.     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    33.     <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    34.     <uses-permission-sdk-23 android:name="android.permission.READ_CALENDAR"/>
    35.     <uses-permission-sdk-23 android:name="android.permission.WRITE_CALENDAR"/>
    36.     <uses-permission android:name="android.permission.READ_CONTACTS" />
    37.     <uses-permission android:name="android.permission.ACTIVITY_RECOGNITION"/>
    38.  
    39.     <!-- ANDROID GOODIES TEST APP PERMISSIONS -->
    40.  
    41.     <!-- Modify screen brightness -->
    42.     <uses-permission android:name="android.permission.WRITE_SETTINGS"/>
    43.  
    44.     <uses-permission android:name="com.android.alarm.permission.SET_ALARM"/>
    45.  
    46.     <!-- To open bluetooth settings on some devices -->
    47.     <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
    48.  
    49.     <uses-permission android:name="android.permission.VIBRATE"/>
    50.  
    51.     <!-- To be able to set phone wallpaper -->
    52.     <uses-permission android:name="android.permission.SET_WALLPAPER"/>
    53.  
    54.     <!-- For dialing phone number directly functionality -->
    55.     <uses-permission android:name="android.permission.CALL_PHONE"/>
    56.  
    57.     <!-- For GPS coordinates -->
    58.     <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    59.     <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    60.     <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
    61.     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    62.     <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
    63.  
    64.     <!-- For some Telephony methods -->
    65.     <uses-permission android:name="android.permission.MODIFY_PHONE_STATE"/>
    66.     <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
    67.  
    68.     <!-- Flashlight & Taking photos -->
    69.     <uses-permission android:name="android.permission.CAMERA" android:required="false"/>
    70.     <uses-feature android:name="android.hardware.camera"/>
    71.  
    72.     <uses-permission android:name="android.permission.FLASHLIGHT"/>
    73.     <uses-feature android:name="android.hardware.camera.flash" android:required="false"/>
    74.  
    75.     <!-- For testing runtime permissions -->
    76.     <uses-permission android:name="android.permission.WRITE_CONTACTS"/>
    77.     <uses-permission android:name="android.permission.READ_CALENDAR"/>
    78.     <uses-permission android:name="android.permission.GET_ACCOUNTS"/>
    79.  
    80.     <!-- For contact picker -->
    81.     <uses-permission android:name="android.permission.READ_CONTACTS"/>
    82.  
    83.     <!-- For fingerprint scanner -->
    84.     <uses-permission android:name="android.permission.USE_FINGERPRINT"/>
    85.  
    86.     <!-- For audio recording -->
    87.     <uses-permission android:name="android.permission.RECORD_AUDIO" />
    88.  
    89.     <!-- For wifi management -->
    90.     <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
    91.  
    92.     <!-- For GPS coordinates -->
    93.     <!-- Needed only if your app targets Android 5.0 (API level 21) or higher. -->
    94.     <uses-feature android:name="android.hardware.location.gps" android:required="false"/>
    95.     <!-- END ANDROID GOODIES TEST APP PERMISSIONS -->
    96.  
    97.     <uses-feature android:name="android.hardware.touchscreen" android:required="false"/>
    98.     <uses-feature android:name="android.hardware.touchscreen.multitouch" android:required="false"/>
    99.     <uses-feature android:name="android.hardware.touchscreen.multitouch.distinct" android:required="false"/>
    100.  
    101. </manifest>
    102.  
    In my code, I'm trying to pop the permission box by:
    Code (CSharp):
    1.  
    2.         AndroidRuntimePermissions.Permission result = AndroidRuntimePermissions.RequestPermission("android.permission.ACTIVITY_RECOGNITION");
    3.         if (result == AndroidRuntimePermissions.Permission.Granted)
    4.         {
    5.             Debug.Log("We have permission to access the stepcounter");
    6.         }
    7.         else
    8.         {
    9.             Debug.Log("Permission state: " + result); // No permission
    10.             Application.Quit();
    11.         }
    Thank you for your amazing assets.
     
  35. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    I was able to see the permission dialog on a new 2018.4 project. Can you also test it on a new project? If it works, please change Player Settings iteratively until you find the culprit. Also, I'd recommend you to check logcat to see if there are any error messages.

    screenshot.png
     
  36. Sashimiii

    Sashimiii

    Joined:
    Sep 26, 2017
    Posts:
    15
    Hi! I've tested it in a new project, but after building I get this error:

    Code (CSharp):
    1. 01/27 09:52:55.528 6151 6151 Error AndroidRuntime FATAL EXCEPTION: main
    2. 01/27 09:52:55.528 6151 6151 Error AndroidRuntime Process: com.google.android.packageinstaller, PID: 6151
    3. 01/27 09:52:55.528 6151 6151 Error AndroidRuntime java.lang.RuntimeException: Unable to start activity ComponentInfo{com.google.android.packageinstaller/com.android.packageinstaller.permission.ui.GrantPermissionsActivity}: java.lang.NullPointerException: Attempt to get length of null array
    4. 01/27 09:52:55.528 6151 6151 Error AndroidRuntime     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2432)
    5. 01/27 09:52:55.528 6151 6151 Error AndroidRuntime     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2492)
    6. 01/27 09:52:55.528 6151 6151 Error AndroidRuntime     at android.app.ActivityThread.access$900(ActivityThread.java:156)
    7. 01/27 09:52:55.528 6151 6151 Error AndroidRuntime     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1352)
    8. 01/27 09:52:55.528 6151 6151 Error AndroidRuntime     at android.os.Handler.dispatchMessage(Handler.java:102)
    9. 01/27 09:52:55.528 6151 6151 Error AndroidRuntime     at android.os.Looper.loop(Looper.java:148)
    10. 01/27 09:52:55.528 6151 6151 Error AndroidRuntime     at android.app.ActivityThread.main(ActivityThread.java:5469)
    11. 01/27 09:52:55.528 6151 6151 Error AndroidRuntime     at java.lang.reflect.Method.invoke(Native Method)
    12. 01/27 09:52:55.528 6151 6151 Error AndroidRuntime     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    13. 01/27 09:52:55.528 6151 6151 Error AndroidRuntime     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
    14. 01/27 09:52:55.528 6151 6151 Error AndroidRuntime Caused by: java.lang.NullPointerException: Attempt to get length of null array
    15. 01/27 09:52:55.528 6151 6151 Error AndroidRuntime     at com.android.packageinstaller.permission.ui.GrantPermissionsActivity.computePermissionGrantState(GrantPermissionsActivity.java:312)
    16. 01/27 09:52:55.528 6151 6151 Error AndroidRuntime     at com.android.packageinstaller.permission.ui.GrantPermissionsActivity.updateDefaultResults(GrantPermissionsActivity.java:362)
    17. 01/27 09:52:55.528 6151 6151 Error AndroidRuntime     at com.android.packageinstaller.permission.ui.GrantPermissionsActivity.onCreate(GrantPermissionsActivity.java:105)
    18. 01/27 09:52:55.528 6151 6151 Error AndroidRuntime     at android.app.Activity.performCreate(Activity.java:6555)
    19. 01/27 09:52:55.528 6151 6151 Error AndroidRuntime     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
    20. 01/27 09:52:55.528 6151 6151 Error AndroidRuntime     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2385)
    21. 01/27 09:52:55.528 6151 6151 Error AndroidRuntime     ... 9 more
    22.  
    It's in Unity version 2019.4.4f on a Lenovo P2A42, Android version 6.
     
  37. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    I can't reproduce the issue on an Android 7.1 emulator which is the closest setup I have. I'm using Android API 29 as Target API Level, if it matters. There are multiple threads on google about this error and they all come to the same conclusion: the permission is either not declared in AndroidManifest or is declared inside application tag by mistake. I don't see any of these issues in your manifest but I get the impression that the permission isn't included in the merged AndroidManifest for some reason. You can test it by looking at Temp/StagingArea/AndroidManifest.xml's contents after building the game.
     
  38. Sashimiii

    Sashimiii

    Joined:
    Sep 26, 2017
    Posts:
    15
    This directory you've pointed me to is completely empty. It does have a data map, but that one is empty as well. Not sure why. I've included the same manifest as the other project in this empty project.

     
  39. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Directory may be cleared after closing Unity. You need to open Unity, build the game and then refresh the folder.
     
  40. Sashimiii

    Sashimiii

    Joined:
    Sep 26, 2017
    Posts:
    15
    Thank you, I didn't know.

    I've done accordingly, and the xml file in the StagingArea shows the following:
    Code (CSharp):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="com.unity3d.player" android:versionName="1.0" android:versionCode="1" android:installLocation="preferExternal">
    3.   <supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true" />
    4.   <uses-feature android:glEsVersion="0x00020000" />
    5.   <supports-gl-texture android:name="GL_OES_compressed_ETC1_RGB8_texture" />
    6.   <application android:theme="@style/UnityThemeSelector" android:label="@string/app_name" android:debuggable="true" android:isGame="true" android:icon="@mipmap/app_icon">
    7.     <activity android:name="com.unity3d.player.UnityPlayerActivity" android:label="@string/app_name" android:screenOrientation="fullSensor" android:launchMode="singleTask" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale|layoutDirection|density" android:hardwareAccelerated="false">
    8.       <intent-filter>
    9.         <action android:name="android.intent.action.MAIN" />
    10.         <category android:name="android.intent.category.LAUNCHER" />
    11.         <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
    12.       </intent-filter>
    13.       <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
    14.       <meta-data android:name="android.notch_support" android:value="true" />
    15.     </activity>
    16.     <!-- Unity requests all the runtime permissions when you application starts, all in a row. Uncomment these lines to prevent this from happening-->
    17.     <!--<meta-data-->
    18.     <!--android:name="unityplayer.SkipPermissionsDialog"-->
    19.     <!--android:value="true"/>-->
    20.     <meta-data android:name="unity.splash-mode" android:value="0" />
    21.     <meta-data android:name="unity.splash-enable" android:value="True" />
    22.     <meta-data android:name="notch.config" android:value="portrait|landscape" />
    23.     <meta-data android:name="unity.build-id" android:value="052527e4-bc70-4801-9b9b-7408c23bdc4c" />
    24.   </application>
    25.   <!-- PERMISSIONS -->
    26.   <uses-permission android:name="android.permission.INTERNET" />
    27.   <uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />
    28.   <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    29.   <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    30.   <!-- ANDROID GOODIES TEST APP PERMISSIONS -->
    31.   <!-- Modify screen brightness -->
    32.   <uses-permission android:name="android.permission.WRITE_SETTINGS" />
    33.   <uses-permission android:name="com.android.alarm.permission.SET_ALARM" />
    34.   <!-- To open bluetooth settings on some devices -->
    35.   <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
    36.   <uses-permission android:name="android.permission.VIBRATE" />
    37.   <!-- To be able to set phone wallpaper -->
    38.   <uses-permission android:name="android.permission.SET_WALLPAPER" />
    39.   <!-- For dialing phone number directly functionality -->
    40.   <uses-permission android:name="android.permission.CALL_PHONE" />
    41.   <!-- For GPS coordinates -->
    42.   <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    43.   <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    44.   <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    45.   <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    46.   <!-- For some Telephony methods -->
    47.   <uses-permission android:name="android.permission.MODIFY_PHONE_STATE" />
    48.   <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    49.   <!-- For silent SMS -->
    50.   <uses-permission android:name="android.permission.SEND_SMS" />
    51.   <!-- Flashlight & Taking photos -->
    52.   <uses-permission android:name="android.permission.CAMERA" android:required="false" />
    53.   <uses-feature android:name="android.hardware.camera" />
    54.   <uses-permission android:name="android.permission.FLASHLIGHT" />
    55.   <uses-feature android:name="android.hardware.camera.flash" android:required="false" />
    56.   <!-- For testing runtime permissions -->
    57.   <uses-permission android:name="android.permission.WRITE_CONTACTS" />
    58.   <uses-permission android:name="android.permission.READ_CALENDAR" />
    59.   <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    60.   <!-- For contact picker -->
    61.   <uses-permission android:name="android.permission.READ_CONTACTS" />
    62.   <!-- For fingerprint scanner -->
    63.   <uses-permission android:name="android.permission.USE_FINGERPRINT" />
    64.   <!-- For audio recording -->
    65.   <uses-permission android:name="android.permission.RECORD_AUDIO" />
    66.   <!-- For wifi management -->
    67.   <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
    68.   <!-- For GPS coordinates -->
    69.   <!-- Needed only if your app targets Android 5.0 (API level 21) or higher. -->
    70.   <uses-feature android:name="android.hardware.location.gps" android:required="false" />
    71.   <!-- END ANDROID GOODIES TEST APP PERMISSIONS -->
    72.   <uses-feature android:name="android.hardware.touchscreen" android:required="false" />
    73.   <uses-feature android:name="android.hardware.touchscreen.multitouch" android:required="false" />
    74.   <uses-feature android:name="android.hardware.touchscreen.multitouch.distinct" android:required="false" />
    75.   <uses-feature android:name="android.hardware.vulkan.version" android:required="false" />
    76. </manifest>
    77.  
     
  41. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    What is your Target API Level?
     
  42. Sashimiii

    Sashimiii

    Joined:
    Sep 26, 2017
    Posts:
    15
    Automatic (highest installed).
     
  43. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    What is the highest installed API Level? Mine is Android 29 but 30 should also work. Can you also try the plugin on another device?
     
  44. Sashimiii

    Sashimiii

    Joined:
    Sep 26, 2017
    Posts:
    15
    Highest is 30 for me, I'll try another device!
     
    yasirkula likes this.
  45. gaglabs

    gaglabs

    Joined:
    Oct 17, 2019
    Posts:
    185
    Yas, I tried importing the asset through the asset store and through git and both times I get AndroidRuntimePermissions null reference. Is there some add on I'm supposed to have for this to work?
     
  46. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    You don't need any additional assets. At which line do you get the error? Is it a runtime error or a compiler error? Can you post the full error message?
     
  47. gaglabs

    gaglabs

    Joined:
    Oct 17, 2019
    Posts:
    185
    There is no error. When I use the reference AndroidRuntimePermissions as instructed, it says that it csnt find ant assembly reference to AndroidRuntimePermissions
     
  48. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    If you are using your own Assembly Definition Files, you need to add AndroidRuntimePermissions.Runtime.asmdef as reference to them.
     
  49. gaglabs

    gaglabs

    Joined:
    Oct 17, 2019
    Posts:
    185
    But im not. I imported your package. Then when a user wants to use thier device cam it should run your above code

    AndroidRuntimePermissions.Permission

    But it can't find the reference AnroidRuntimePermissions..
     
  50. gaglabs

    gaglabs

    Joined:
    Oct 17, 2019
    Posts:
    185
    I see your script in Plugins/Android/AndroidRuntimePermissions labeled AndroidRuntimePermissions