I tried establishing a Bluetooth connection via Unity in 2d configuration on Android.
Therefore i wrote a plugin calling
BluetoothAdapter btad = BluetoothAdapter.getDefaultAdapter();
but when i execute this on my Galaxy S4 the adapter is null, so this would mean that there is no Bluetooth adapter. I'm now a little bit confused why this happens and how to solve it...
Even
btad=(BluetoothAdapter) getSystemService(BLUETOOTH_SERVICE);
is not working.
Btw: I tested the plugin and it works, but the bluetooth connect-method returns that the adapter is null...
The Class-code is
import java.util.List;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
public class Btconnector extends Activity {
private static final int REQUEST_ENABLE_BT = 267;
boolean bton;
BluetoothAdapter btad = BluetoothAdapter.getDefaultAdapter();
public boolean connect() {
btad = BluetoothAdapter.getDefaultAdapter();
if(btad==null)
{
btad=(BluetoothAdapter) getSystemService(BLUETOOTH_SERVICE);
}
if (btad != null) {
if (!btad.isEnabled()) {
bton = false;
Intent enableBtIntent = new Intent(
BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
} else {
bton = true;
listcon();
}
return true;
} else {
return false;
}
} //[...]