我正在尝试开发一个Android应用程序,它将使用蓝牙功能将数据从芯片传输到Android手机。我没有更改开发人员网站上的教程中的代码。
我收到以下错误:
_context cannot be resolved as a variable
这是我的代码:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LocalBluetoothDevice localBT = LocalBluetoothDevice.initLocalDevice(_context);
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (mBluetoothAdapter == null) {
// Device does not support Bluetooth
}
if (!mBluetoothAdapter.isEnabled()) {
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
}
}
答案 0 :(得分:0)
使用
LocalBluetoothDevice localBT = LocalBluetoothDevice.initLocalDevice(this);
或
Context context = this;
LocalBluetoothDevice localBT = LocalBluetoothDevice.initLocalDevice(context);