我已准备好用户界面,但我真的不知道如何创建连接到手机上已配对设备的逻辑?....我对这一切都很新,我会很感激帮助。
这就是我的Main.java文件:
package com.example.mustangsound;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
public class MainActivity extends Activity {
BluetoothAdapter mBluetoothAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void BTConnect (){
}
public void LightsOn (){
}
public void LightsOff (){
}
public void DoorsOpen (){
}
public void DoorsClose (){
}
public void SysOn (){
}
public void SysOff (){
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
我想在public void BTConnect()中添加代码。再次感谢您的帮助。
答案 0 :(得分:0)
BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(“设备的蓝牙地址在这里”);
然后你调用一个BluetoothDevice方法来建立你想要的任何类型的连接。例如,RFCOMM连接看起来像这样:
BluetoothSocket socket = device.createInsecureRfcommSocketToServiceRecord(UUID.fromString(“0000111F-0000-1000-8000-00805F9B34FB”));
用于免提设备。