Hola amigos recientemente e encontrado esta clase de android que si no me equivoco perite enviar un texto a un dispositivo previamente pareado
Código Javascript
:
Ver originalpublic class BluetoothWorker {
private static UUID generalUuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
private static BluetoothSocket socket;
private static BluetoothSocket getBluetoothSocket(){
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
mBluetoothAdapter.cancelDiscovery();
Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
// If there are paired devices
if (pairedDevices.size() > 0) {
// Loop through paired devices
for (BluetoothDevice device : pairedDevices) {
// Add the name and address to an array adapter to show in a ListView
if(device.getName().equalsIgnoreCase(("MIGUEL-PC"))){
try {
return device.createRfcommSocketToServiceRecord(generalUuid);
} catch (IOException e) {
return null;
}
}
}
}
return null;
}
public static boolean sendData(String status){
socket = getBluetoothSocket();
try {
socket.connect();
} catch (IOException e) {
// TODO Auto-generated catch block
socket = null;
}
if(socket != null){
try {
socket.getOutputStream().write(status.getBytes());
socket.getOutputStream().flush();
socket.close();
return true;
} catch (IOException e) {
socket = null;
return false;
}
}else{
return false;
}
}
}
mi pregunta es como lo colocaria en mi activiti principal y como invocarlo por ejemplo al pulsar un boton, gracias
NOTA: el autor del texto dice que falla habeces ,si alguien lo sabe mejorar se agradece