Ser*_*uan 47 android bluetooth
我正在尝试这样做:
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);
}
}
Run Code Online (Sandbox Code Playgroud)
但我得到这个错误:
REQUEST_ENABLE_BT无法解析为变量
我该如何解决?
Dee*_*eeV 105
REQUEST_ENABLE_BT是您提供的请求代码.它实际上只是您提供的一个数字onActivityResult.它将是活动返回时的requestCode(第一个参数)onActivityResult.你可以输入你想要的任何数字,只要它在return方法中是一致的.
换句话说,将这样的行放在Activity的顶部:
private final static int REQUEST_ENABLE_BT = 1;
| 归档时间: |
|
| 查看次数: |
36352 次 |
| 最近记录: |