Java 如何通过蓝牙从芯片传输数据?
我正在尝试开发一个android应用程序,它将使用蓝牙功能将数据从芯片传输到android手机。我根本没有更改开发人员网站上教程中的代码 我得到以下错误:Java 如何通过蓝牙从芯片传输数据?,java,android,bluetooth,Java,Android,Bluetooth,我正在尝试开发一个android应用程序,它将使用蓝牙功能将数据从芯片传输到android手机。我根本没有更改开发人员网站上教程中的代码 我得到以下错误: \u无法将上下文解析为变量 这是我的密码: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); LocalBluetoothDevice
\u无法将上下文解析为变量
这是我的密码:
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);
}
}
使用
或
当我尝试这一点时,它出现了一个错误:initLocalDevice对于类型LocalBluetoothDevice是未定义的,这是您项目的主要活动?您需要执行Context Context=YourMainActivity.this,然后使用它
LocalBluetoothDevice localBT = LocalBluetoothDevice.initLocalDevice(this);
Context context = this;
LocalBluetoothDevice localBT = LocalBluetoothDevice.initLocalDevice(context);