I am trying to do bluetooth communication in unity project through android plugin and at the beginning I want to turn on bluetooth.
The java code look like this
package com.example.unityplugin;
import android.bluetooth.BluetoothAdapter;
public class PluginClass {
public static String testMessage(){
return "I AM WORKING";
}
public static String TurnOnBluetooth(){
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (bluetoothAdapter != null) {
if (!bluetoothAdapter.isEnabled()) {
bluetoothAdapter.enable();
return "BLUETOOTH ON";
} else {
return "WAS ON";
}
}
return "no bluetooth adapter";
}
}
And in Unity is as simple as
void Start () {
textMEsh = GetComponent<TextMesh>();
var plugin = new AndroidJavaClass("com.example.unityplugin.PluginClass");
textMEsh.text = plugin.CallStatic<string>("testMessage");
textMEsh.text = plugin.CallStatic<string>("TurnOnBluetooth");
}
So the text displaying in app changes after first method "testMessage" to "I AM WORKING" but then nothing happens and I don't really understand why. Bluetooth is not turning on and I see the following error from the log:
I/Unity: AndroidJavaException: java.lang.SecurityException: Need BLUETOOTH ADMIN permission: Neither user 10069 nor current process has android.permission.BLUETOOTH_ADMIN.
How should I properly set that permission in Unity?