Я работаю над проектом Unity Android, в котором я использую службу сканирования Bluetooth. У меня начались проблемы с подключением по Bluetooth, когда я обновился до Android 10 (API 29). Я получаю помощь из этого сообщения (ссылка ниже), где упоминается, что с Android 10 и далее необходимо включить разрешение BACKGROUND_LOCATION
.
Android 10 не работает со сканированием BLE Bluetooth
В Unity я написал некоторый код, используя служебный инструмент разрешения
if (AndroidRuntimePermissions.CheckPermission(Permission.CoarseLocation) != AndroidRuntimePermissions.Permission.Granted)
{
AndroidRuntimePermissions.RequestPermission(Permission.CoarseLocation);
}
Permission
класс - это внутренний класс из UnityEngine.Android
, который, похоже, не имеет фона разрешение на размещение. См. Ниже:
using UnityEngine.Scripting;
/// <summary>
/// <para>Structure describing a permission that requires user authorization.</para>
/// </summary>
[NativeHeader ("Runtime/Export/Android/AndroidPermissions.bindings.h")]
[UsedByNativeCode]
public struct Permission
{
/// <summary>
/// <para>Used when requesting permission or checking if permission has been granted to use the camera.</para>
/// </summary>
public const string Camera = "android.permission.CAMERA";
/// <summary>
/// <para>Used when requesting permission or checking if permission has been granted to use the microphone.</para>
/// </summary>
public const string Microphone = "android.permission.RECORD_AUDIO";
/// <summary>
/// <para>Used when requesting permission or checking if permission has been granted to use the users location with high precision.</para>
/// </summary>
public const string FineLocation = "android.permission.ACCESS_FINE_LOCATION";
/// <summary>
/// <para>Used when requesting permission or checking if permission has been granted to use the users location with coarse granularity.</para>
/// </summary>
public const string CoarseLocation = "android.permission.ACCESS_COARSE_LOCATION";
/// <summary>
/// <para>Used when requesting permission or checking if permission has been granted to read from external storage such as a SD card.</para>
/// </summary>
public const string ExternalStorageRead = "android.permission.READ_EXTERNAL_STORAGE";
/// <summary>
/// <para>Used when requesting permission or checking if permission has been granted to write to external storage such as a SD card.</para>
/// </summary>
public const string ExternalStorageWrite = "android.permission.WRITE_EXTERNAL_STORAGE";
/// <summary>
/// <para>Check if the user has granted access to a device resource or information that requires authorization.</para>
/// </summary>
/// <param name="permission">A string representing the permission to request. For permissions which Unity has not predefined you may also manually provide the constant value obtained from the Android documentation here: https:developer.android.comguidetopicspermissionsoverview#permission-groups such as "android.permission.READ_CONTACTS".</param>
/// <returns>
/// <para>Whether the requested permission has been granted.</para>
/// </returns>
[MethodImpl (MethodImplOptions.InternalCall)]
[StaticAccessor ("PermissionsBindings", StaticAccessorType.DoubleColon)]
public static extern bool HasUserAuthorizedPermission (string permission);
/// <summary>
/// <para>Request that the user grant access to a device resource or information that requires authorization.</para>
/// </summary>
/// <param name="permission">A string that describes the permission to request. For permissions which Unity has not predefined you may also manually provide the constant value obtained from the Android documentation here: https:developer.android.comguidetopicspermissionsoverview#permission-groups such as "android.permission.READ_CONTACTS".</param>
[MethodImpl (MethodImplOptions.InternalCall)]
[StaticAccessor ("PermissionsBindings", StaticAccessorType.DoubleColon)]
public static extern void RequestUserPermission (string permission);
}
Пожалуйста, дайте мне знать, если вы нашли способ решить эту проблему. Ваша помощь очень ценится. Спасибо.