Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question How to allow android permissions on plugins

Discussion in 'Android' started by elliot_eserin, Feb 3, 2022.

  1. elliot_eserin

    elliot_eserin

    Joined:
    Jan 5, 2020
    Posts:
    38
    Hi,
    I have created an android plugin (which includes a background service) which all works fine, but I want the service to scan and connect to Bluetooth LE beacons. This is fine, I implement the code to do it but when it comes to running it, there are two permissions it needs:
    • BLUETOOTH_SCAN
    • BLUETOOTH_CONNECT
    But I cant work out how to enable these permissions... I have added them to both manifest files (the Unity project and the Android Plugin (Im not entirely sure what the difference is or which one is needed)) and I have tried using
    UnityEngine.Android.Permission.RequestUserPermissions(permissions);
    to request the permissions. This worked with the background location permission, but I cant get it to work with the Bluetooth permissions... and Im not sure how to do it.

    Also will granting those permissions in Unity give those permissions to the plugin? or should I really be implementing the permission requests from the plugin side?

    Thanks for any help!
     
  2. elliot_eserin

    elliot_eserin

    Joined:
    Jan 5, 2020
    Posts:
    38
    I have also tried:
    Code (CSharp):
    1.         String[] perms= new String[1];
    2.         perms[0]=Manifest.permission.BLUETOOTH_SCAN;
    3.  
    4.         if (ContextCompat.checkSelfPermission(myActivity, perms[0])
    5.                 != PackageManager.PERMISSION_GRANTED) {
    6.             ActivityCompat.requestPermissions(myActivity,
    7.                     perms,
    8.                     1);
    In the plugin but that seems to do nothing...
     
  3. Omid7L

    Omid7L

    Joined:
    Jun 10, 2018
    Posts:
    14
    Did you find any solution?
     
  4. KellanUnfiller

    KellanUnfiller

    Joined:
    Feb 7, 2023
    Posts:
    2
    Bump as well!
     
  5. elliot_eserin

    elliot_eserin

    Joined:
    Jan 5, 2020
    Posts:
    38
    Im afraid I gave up and just made the application completely natively... I hope you are able to find a workaround
     
  6. seiji_unity623

    seiji_unity623

    Joined:
    Oct 15, 2022
    Posts:
    6
    Hi, I am working on something similar, how did you request the background location permission using UnityEngine.Android.Permission.RequestUserPermissions(permissions)? it looks like it only supports fine/coarse location permissions rather than the separate background location permissions. Any help with this would be great!