Bluetooth Problems - InquiryError if GPS on, Service Discovery Problems..
Hey Guys!
I've tried to write a simple bluetooth programm, that can send strings between two phones, but nothing really wants to work on my benq/siemens C81(=S75) or E71!!!
first Problem is, as soon as my GPS Device Holux GPSlim236 is turned on, I can't perform a Device Search! It always returns InquiryError! if the gps is turned off, I can correctly detect a lot of other devices and search their services...but only if the gps is off o.o
these are parts of my code:
/***Eigene Bluetooth-Informationen anzeigen***/
// retrieve the local Bluetooth device object
LocalDevice local = LocalDevice.getLocalDevice();
// retrieve the Bluetooth address of the local device
String address = local.getBluetoothAddress();
// retrieve the name of the local Bluetooth device
Client.append("\n"+address+"\n"+ownname+"\n");
/***Bluetooth-Ger鋞esuche starten***/
//den DiscoveryAgent deklarieren
Client.append("\nStarting BT\n");
DiscoveryAgent agent = local.getLocalDevice().getDiscoveryAgent();
//letztes gefundenes Ger鋞
btDev =null;
//Damit das Array, das die gefundenen Ger鋞e enth鋖t, beschreibselt werden kann
FoundDevicesNum = 0;
//suche starten
agent.startInquiry(DiscoveryAgent.GIAC,this);
Client.append("\nSearching...\n");
.............
publicvoid deviceDiscovered(RemoteDevice remoteDevice, DeviceClass deviceClass){
btDev = remoteDevice;
//((Form)Display.getDisplay(this).getCurrent()).append(btDev.getBluetoothAddress()+"\n");
FoundDevices[FoundDevicesNum] = btDev;
FoundDevicesNum++;
}
publicvoid inquiryCompleted(int discType){
if (discType == DiscoveryListener.INQUIRY_COMPLETED)
{
if(btDev ==null){
((Form)Display.getDisplay(this).getCurrent()).append("No device has been discovered!");
}
else
{
//((Form)Display.getDisplay(this).getCurrent()).append("Inquiry completed.");
List FoundDevicesSelection =new List("Select Device",Choice.IMPLICIT);
for (int o=0;o<FoundDevicesNum;o++)
try{FoundDevicesSelection.append( FoundDevices[o].getFriendlyName(false),null);}
catch (IOException ex){Display.getDisplay(this).setCurrent(new Alert("!",ex.toString(),null,AlertType.INFO));}
FoundDevicesSelection.addCommand(new Command("Back", Command.BACK, 1));
FoundDevicesSelection.setSelectCommand(new Command("OK",Command.OK,0));
FoundDevicesSelection.setCommandListener(this);
Display.getDisplay(this).setCurrent(FoundDevicesSelection);
}
}else
if (discType == DiscoveryListener.INQUIRY_TERMINATED)
{((Form)Display.getDisplay(this).getCurrent()).append("\nInquiry Terminated");}
elseif (discType == DiscoveryListener.INQUIRY_ERROR)
{((Form)Display.getDisplay(this).getCurrent()).append("\nInquiry Error");}
}
Could anybody explain that to me? seems really strange...
And my next problem is, that on my phone everything seems to be a bit strange! I've only got 2 of my C81's and only one S/E W810i to test, but I cant find a server created on a C81 with a C81!
What works and what doesnt:
W810 creates Server - C81 uses normal Device Search, then Service Search - it detects normal SerialPort and my Server and runs PERFECTLY
W810 creates Server - C81 uses simple Service Search - it DOESNT find the server on the w810i
C81 creates Server - W810i uses normal Device Search, then Service Search - it only detects the devices default serialport, and NOT my own server....
C81 creates Server - W810i uses simple Service Search - it finds my own service and runs PERFECTLY
so, as you see, the other phone can only connect to the C81 server via simple service search, the device and then service search can't find the C81 server!
but also, on the C81 the simple service search doesn't work!
so right now I can't connect to C81's with each other, cause it simply doesnt work! I dont know if its of any help if I post my whole code...maybe I'll just post how the server is launched:
publicvoid run()
{
StringItem received_msg =null;
//SERVER krams
if (type.equals("server"))
{
String name ="JavaStars06";//the name of the service
String url ="btspp://localhost:" + uuid//the service url
+";name=" + name
+";master=false;authenticate=false;authorize=false;encrypt=false";
LocalDevice local =null;//?
StreamConnectionNotifier server =null;
byte buffer[] =newbyte[100];
try{
//((Form)Display.getDisplay(this).getCurrent()).append("\nSetting device discoverable...");
local = LocalDevice.getLocalDevice();
local.setDiscoverable(DiscoveryAgent.GIAC);
ownname = local.getFriendlyName();
//((Form)Display.getDisplay(this).getCurrent()).append("\nStart advertising service...");
server = (StreamConnectionNotifier)Connector.open(url);
// Retrieve the service record template
local.getRecord( server ).setAttributeValue( 0x0008,new DataElement( DataElement.U_INT_1, 0xFF ) );
// set ServiceAvailability (0x0008) attribute to indicate our service is available
// 0xFF indicate fully available status
// This operation is optional
((Form)Display.getDisplay(this).getCurrent()).append("\nWaiting for incoming connection...");
connection = server.acceptAndOpen();
((Form)Display.getDisplay(this).getCurrent()).deleteAll();
String othername = RemoteDevice.getRemoteDevice(connection).getFriendlyName(false);
//othername = "othername";
//ownname = "ownname";
((Form)Display.getDisplay(this).getCurrent()).append("\n"+othername+" connected!");
InputStream is = connection.openInputStream();
os = connection.openOutputStream();
while(true)
{
String cmd ="";
int m = is.read(buffer);
for (int i=0;i<m;i++ )
cmd = cmd + (char)buffer[i];
if (Chat.size()>1)
{
received_msg = (StringItem) Chat.get(Chat.size()-1);
if (received_msg.getLabel().equals(othername)==true)
{
received_msg.setText(received_msg.getText()+"\n"+cmd);
}
else
{
received_msg =new StringItem(othername, cmd);
received_msg.setLayout(Item.LAYOUT_NEWLINE_BEFORE);
received_msg.setFont(font);
Chat.append(received_msg);
}
}
else
{
received_msg =new StringItem(othername, cmd);
received_msg.setLayout(Item.LAYOUT_NEWLINE_BEFORE);
received_msg.setFont(font);
Chat.append(received_msg);
}
if (Display.getDisplay(this).getCurrent().getTitle().equals("BT-Test")==true)
{ Chat.append("\nshutdown thread");break;}
}
connection.close();
}catch (Exception e){Chat.append("Exception Occured: " + e.toString());}
}

