I am looking for a way to turn on Bluetooth on Android and iOS devices from inside my unity application or to trigger a prompt to ask the user for this (like in the example img).
Does anyone know of an asset, that can help me with this or if Unity has this feature already?
public void setBluetoothEnabled()
{
using (AndroidJavaObject activity = new AndroidJavaClass(“com.unity3d.player.UnityPlayer”).GetStatic(“currentActivity”))
{
try
{
using (var BluetoothManager = activity.Call(“getSystemService”, “bluetooth”))
{
using (var BluetoothAdapter = BluetoothManager.Call(“getAdapter”))
{
BluetoothAdapter.Call(“enable”);
}
}
}
catch (Exception e)
{
}
}
}
@KuboRobot This will silently turn on bluetooth, without pop-ups because you grant permissions while installing an app, also, you have to add this to your AndroidManifest.xml:
uses-permission android:name="android.permission.BLUETOOTH_ADMIN"
uses-permission android:name="android.permission.BLUETOOTH" (probably not needed)