Bluetooth Document
Bluetooth Document
import javax.bluetooth.DiscoveryAgent;
import javax.bluetooth.LocalDevice;
import javax.microedition.io.Connector;
import javax.microedition.io.StreamConnection;
import javax.microedition.io.StreamConnectionNotifier;
public ServerChat()
{
startServerChatBluetooth();
}
LocalDevice.getLocalDevice().setDiscoverable(DiscoveryAgent.GIAC);
}
catch(Exception error)
{
error.printStackTrace();
}
try
{
stream_connection_notifier = (StreamConnectionNotifier)
Connector.open("btspp://localhost:" + CHATTANDO_UUID + ";name=" + CHATTANDO_SERVICE);
}
catch(Exception error)
{
error.printStackTrace();
}
stopServerChatBluetooth();
stream_connection =
stream_connection_notifier.acceptAndOpen();
System.out.println("Client Connected");
}
}
catch(Exception error)
{
error.printStackTrace();
}
}
}.start();
}
try
{
stream_connection_notifier.close();
}
catch(Exception error)
{
error.printStackTrace();
}
}
}
}
search service......
import java.util.Vector;
import javax.bluetooth.DeviceClass;
import javax.bluetooth.DiscoveryAgent;
import javax.bluetooth.DiscoveryListener;
import javax.bluetooth.LocalDevice;
import javax.bluetooth.RemoteDevice;
import javax.bluetooth.ServiceRecord;
import javax.bluetooth.UUID;
startScanBluetoothDevices();
}
discovery_agent = LocalDevice.getLocalDevice().getDiscoveryAgent();
discovery_agent.startInquiry(DiscoveryAgent.GIAC, this);
}
catch(Exception error)
{
error.printStackTrace();
}
}
case DiscoveryListener.INQUIRY_ERROR:
break;
case DiscoveryListener.INQUIRY_TERMINATED:
break;
}
try
{
for(int i=0, cnt=remote_device.size(); i<cnt; i++)
{
discovery_agent.searchServices(new int[]{ 0x0100, 0x0200 }, new
UUID[]{ new UUID(0x0003), new UUID(CHATTANDO_UUID, false) }, (RemoteDevice)
remote_device.elementAt(i), this);
waitForSearchDone();
}
}
catch(Exception error)
{
error.printStackTrace();
}
}
try
{
while(!searchDone)
{
synchronized(this)
{
this.wait();
}
}
}
catch(Exception error)
{
}
}
case DiscoveryListener.SERVICE_SEARCH_DEVICE_NOT_REACHABLE:
case DiscoveryListener.SERVICE_SEARCH_ERROR:
case DiscoveryListener.SERVICE_SEARCH_NO_RECORDS:
break;
case DiscoveryListener.SERVICE_SEARCH_TERMINATED:
searchDone = true;
// Risveglia il processo in attesa del completamento della ricerca dei servizi per un
dispositivo
synchronized(this)
{
this.notifyAll();
}
}
Runtime rt = Runtime.getRuntime();
rt.gc(); // Garbage Collection
display.setCurrent(form);
}
stringbuffer.setLength(0);
stringbuffer.append(str);
stringbuffer.append(" = ");
if(value == null)
stringbuffer.append("<undefined>");
else
{
stringbuffer.append("\"");
stringbuffer.append(value);
stringbuffer.append("\"");
}
stringbuffer.append("\n");
return stringbuffer.toString();
}
display.setCurrent(alert);
}
}
sockfd = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
sockfd.connect(('00:00:00:00:00:00', 1)) # BT Address
sockfd.send('ATZ\r')
sockfd.send('AT+CMGF=1\r')
sockfd.send('AT+CSCA="+393359609600"\r') # Client TIM ITA
sockfd.send('AT+CMGS="+39xxxxxxxxxx"\r') # TO PhoneNumber
sockfd.send('Messaggio da mandare...\n')
sockfd.send(chr(26)) # CTRL+Z
sockfd.close()