错误检查如果蓝牙Android中启用(REQUEST_ENABLE_BT不能被解析为一个变量) [英] Error checking if Bluetooth is enabled in Android (REQUEST_ENABLE_BT cannot be resolved to a variable)
问题描述
我试图做到这一点:
BluetoothAdapter bt = BluetoothAdapter.getDefaultAdapter();
if (bt == null){
//Does not support Bluetooth
status.setText("Your device does not support Bluetooth");
}else{
//Magic starts. Let's check if it's enabled
if (!bt.isEnabled()){
Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableIntent, REQUEST_ENABLE_BT);
}
}
不过,我得到这个错误:
But I get this error:
REQUEST_ENABLE_BT不能被解析为一个变量
REQUEST_ENABLE_BT cannot be resolved to a variable
我该如何解决这个问题?
How can I fix it?
推荐答案
REQUEST_ENABLE_BT
为您提供一个请求code。这真的只是一个数字,你为 onActivityResult
。这将是请求code
(第一个参数)活动时的回报。你可以把你想,只要它是在返回的方法是一致的任何数字。 onActivityResult
的
REQUEST_ENABLE_BT
is a request code that you provide. It's really just a number that you provide for onActivityResult
. It will be the requestCode
(first parameter) of onActivityResult
when the activity returns. You could put any number you want as long as it's consistent in the return method.
在换句话说,把这样一行在活动的顶部:
In other words, put a line like this in the top of your Activity:
私人最终静态INT REQUEST_ENABLE_BT = 1;
这篇关于错误检查如果蓝牙Android中启用(REQUEST_ENABLE_BT不能被解析为一个变量)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!