是否可以通过编程方式打开Android设备的蓝牙并与其他设备连接

时间:2015-01-27 13:19:42

标签: javascript android bluetooth apk

我正在尝试使用 android studio 创建一个应用程序,当有来电时它将打开蓝牙并连接到给定设备的名称并最终关闭通话结束后的蓝牙。但我对javascripts的想法较少。所以任何人都可以帮助我吗?请?

2 个答案:

答案 0 :(得分:0)

关于打开和关闭蓝牙并连接到设备,您将找到所需的一切here

要了解如何检测电话,您可以关注this tutorial

干杯!

答案 1 :(得分:0)

我会给你一些提示:

1。)启用蓝牙:

  mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
        if (mBluetoothAdapter != null) {
            if (!mBluetoothAdapter.isEnabled()) {
                Intent enableBtIntent = new Intent(
                        BluetoothAdapter.ACTION_REQUEST_ENABLE);
                startActivity(enableBtIntent);
            } 
   }

2.)连接到设备:

BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);
BluetoothSocket mBluetoothSocket = mBluetoothDevice
                        .createRfcommSocketToServiceRecord(mUUID);
try{
  mBluetoothSocket.connect();
} catch (Exception e){
}