我提出了两项活动的申请。第一个活动导入用户参数,第二个活动通过蓝牙发送数据。如果蓝牙被禁用,我.ACTION_REQUEST_ENABLE会启用它,但是当 bt 关闭时,我的 apk 就会退出。这不起作用。有什么帮助吗?
我用这个;创建活动以及启动处理程序和可运行后的代码...我只测试它 findBT 并工作...
void findBT()
{
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if(mBluetoothAdapter == null)
{
myLabel.setText("No bluetooth adapter available");
}
if(!mBluetoothAdapter.isEnabled())
{
//My problem is there
Intent enableBluetooth = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBluetooth, 0);
}
Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
if(pairedDevices.size() > 0)
{
for(BluetoothDevice device : pairedDevices)
{
if(device.getName().equals(strValue2))
{
mmDevice = device;
break;
}
}
}
myLabel.setText("Bluetooth Device Found");
}
Run Code Online (Sandbox Code Playgroud)