سؤال

When my application starting, I want to check whether the android device is connected to a Bluetooth mouse, and listening to the connected event.

How can I do it?

Thanks!

هل كانت مفيدة؟

المحلول

Using the Android Bluetooth APIs, you can get a list of connected devices like so:

BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();

There's no good way to tell what type of device is connected, but you can run through the devices and their names by iterating through the pairedDevices Set. The Android Bluetooth Guide has a lot more details on Bluetooth.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top