我正在开发一个应用程序来接收蓝牙遥控器的蓝牙命令。所以要求是每当用户点击一个按钮时,我应该向该按钮string sqlquery = "UPDATE TableName set ColumnName1=@param1 where ColumnName2=@param2";
using (OleDbCommand Cmd = new OleDbCommand(sqlQuery, dbCon))
{
Cmd.Parameters.AddWithValue("@param1", Convert.ToDouble(dataGridView1[1, index].Value));
Cmd.Parameters.Add(new OleDbParameter("@param2", OleDbType.VarWChar)).Value = "somevalue";
updateDbCmd.ExecuteNonQuery();
updateDbCmd.Parameters.Clear();
}
致敬。我尝试访问Key_Code
到Bluetooth_Service
类,但无法访问该部分。请帮帮我。
MyCode to getBluetoothDevices:
BluetoothManager
我正在获取设备名称和mac地址等,但没有用于接收命令的活页夹
答案 0 :(得分:1)
有两种方法可以做到这一点。
如果您想从KEY_CODES
接收Activity
Android遥控器,可以直接调用以下方法。它将为您提供按下按钮的所有密钥代码。
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
Toast.makeText(this,"KeyCode is"+keyCode,Toast.LENGTH_LONG).show();
return super.onKeyDown(keyCode, event);
}
注意:使用Android服务无法实现这一点。
客户端:
private class ClietnThread extends Thread{
ClietnThread(BluetoothDevice dev){
mDevice= dev;
}
@Override
public void run() {
super.run();
Log.e(Tag,"Now CONNECTING to"+mDevice.getName());
try{
//mBluetoothSocket =(BluetoothSocket) mDevice.getClass().getMethod("createRfcommSocket", new Class[] {int.class}).invoke(mDevice,1);
mBluetoothSocket = mDevice.createRfcommSocketToServiceRecord(MY_UUID);
mBluetoothSocket.connect();
}catch (IOException e){
Log.e(Tag,"Connect Failed");
e.printStackTrace();
try {
mBluetoothSocket.close();
} catch (IOException closeException) {
Log.e("Client", "Could not close the client socket", closeException);
}
}
}
}
服务器:
private class MyServer extends Thread{
MyServer(){
}
@Override
public void run() {
super.run();
Log.e(Tag,"Bluetooth Listening");
try {
mBluetoothServerSocket = mBluetoothAdapter.listenUsingRfcommWithServiceRecord(NAME, MY_UUID);
mBluetoothAdapter.cancelDiscovery();
}catch (IOException e){
e.printStackTrace();
}
while (true){
try{
BluetoothSocket mSoicket = mBluetoothServerSocket.accept();
Log.e(Tag,"ConnectedToSpike");
}catch (IOException e){
e.printStackTrace();
}
}
}
}