1

I am learning to use Bluetooth in Android. I have given this permission in manifest file

<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>

and the main code lies here:

   private static final int REQUEST_ENABLE_BT = 0;
private static final int REQUEST_DISCOVERABLE_BT = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    final TextView out=(TextView)findViewById(R.id.out);
    final Button button = (Button) findViewById(R.id.button1);
    final Button button1 = (Button) findViewById(R.id.button2);
    final Button button2 = (Button) findViewById(R.id.button3);
    final BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    if (mBluetoothAdapter == null) {
       out.append("device not supported");
    }
    button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            if (!mBluetoothAdapter.isEnabled()) {
                Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
                startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
            }
        }
    });
    button1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View arg0) {
            if (!mBluetoothAdapter.isDiscovering()) {
                   Context context = getApplicationContext();
                   CharSequence text = "MAKING YOUR DEVICE DISCOVERABLE";
                   int duration = Toast.LENGTH_SHORT;
                   Toast toast = Toast.makeText(context, text, duration);
                   toast.show();
                Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
                startActivityForResult(enableBtIntent, REQUEST_DISCOVERABLE_BT);
            }
        }               
    });
    button2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View arg0) {    
            mBluetoothAdapter.disable();
            Context context = getApplicationContext();
               CharSequence text = "TURNING_OFF BLUETOOTH";
               int duration = Toast.LENGTH_SHORT;
               Toast toast = Toast.makeText(context, text, duration);
               toast.show();
            }
    });
}

But it is telling me:

device not supported

on the screen and by clicking on a button makes the app force close so what is the problem with my android emulator?

Alex Lockwood
  • 83,063
  • 39
  • 206
  • 250
abhishek ameta
  • 194
  • 1
  • 12

4 Answers4

3

You need to read this about some limitations of Emulator before using Bluetooth in your application.

CoffeeRain
  • 4,460
  • 4
  • 31
  • 50
2

emulator don't support bluetooth, use real device

idiottiger
  • 5,147
  • 2
  • 25
  • 21
1

device not supported is the message you get when

if (mBluetoothAdapter == null) {
       out.append("device not supported");
    }

That is because the Android emulator does not support Bluetooh. You need a physical device to check Bluetooth enabled applications.

Check these questions for additional info

How to use Bluetooth in Android emulator?
Bluetooth support on Android Emulator

Community
  • 1
  • 1
Ranhiru Jude Cooray
  • 19,542
  • 20
  • 83
  • 128
0

If bluetooth is not supported, then why have a qemu -bt option for the emulator and why is there an emulation for a usb keyboard over bluetooth? Need to enable bluetooth so it appears as supported. There is likely a particular configuration required or a particular target needed beyond adding BOARD_HAVE_BLUETOOTH := true to BoardConfig.mk?

How does one configure bluetooth so it is enabled in the emulator?

bt[:hci-type] Bluetooth dongle whose type is specified in the same format as with the ‘-bt hci’ option, see allowed HCI types. If no type is given, the HCI logic corresponds to -bt hci,vlan=0. This USB device implements the USB Transport Layer of HCI. Example usage:

qemu [...OPTIONS...] -usbdevice bt:hci,vlan=3 -bt device:keyboard,vlan=3

http://wiki.qemu.org/download/qemu-doc.html#usb_005fdevices