×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Nov 2004
    Location
    Rome (Italy)
    Posts
    24

    Angry Bluetooth - Problem with startInquiry() method

    I wrote this simple application for retrieving devices.

    Code:
    public class BluetoothMidlet extends MIDlet implements DiscoveryListener, CommandListener {
    	
    	public Display display;
    	public Form form;
    	private DiscoveryAgent discoveryAgent;
    	private Alert alert;
    	private Command exitCommand;
            private Command cmdsearch; 
            private Command cmdExit;   
        
    	public BluetoothMidlet() {
    		
    	display = Display.getDisplay(this);
            form = new Form("When to sound the alarm:");
            cmdsearch = new Command("Search", Command.SCREEN, 1);
    	cmdExit = new Command("Exit", Command.EXIT, 1); 
    	
            form.addCommand(cmdsearch);
            form.addCommand(cmdExit); 
    	form.setCommandListener(this);
    	}
    
    	protected void startApp() {
    		
    		display.setCurrent(form);		
    	}
    	
    	public void commandAction(Command c, Displayable s) {
    		if (c == cmdsearch) {
    			try {
    				String name = LocalDevice.getLocalDevice().getFriendlyName();
    				String address = LocalDevice.getLocalDevice().getBluetoothAddress();
    				
    				alert = new Alert("My device: " + name + " " + address);
    
    				display.setCurrent(alert,form);
    				discoveryAgent = LocalDevice.getLocalDevice().getDiscoveryAgent();
    
    				discoveryAgent.startInquiry(DiscoveryAgent.GIAC, this);
    
    				
    			} catch (BluetoothStateException e) {
    				e.printStackTrace();
    			}
    	        } else if (c == cmdExit) {
    		    	destroyApp(false);
    		    	notifyDestroyed();
    	    	}
    	}
    
    	protected void pauseApp() {
    
    	}
    
    	protected void destroyApp(boolean arg0) {
    
    	}
    
    	public void deviceDiscovered(RemoteDevice remoteDevice, DeviceClass deviceClass) {
    		
    		Alert alert = new Alert ("deviceDiscovered: " +
    				remoteDevice.getBluetoothAddress() +
    				" major device class=" +
    				deviceClass.getMajorDeviceClass() +
    				" minor device class=" +
    				deviceClass.getMinorDeviceClass() + "\n");
    		display.setCurrent(alert,form);
    		System.out.println("Device discovered");		
    	}
    
    	public void inquiryCompleted(int discoveryType) {
    		
    		Alert alert = new Alert ("Inquiry completed");
    		display.setCurrent(alert,form);
    		System.out.println("Inquiry completed");
    	}
    }
    But this code do nothing when i give command "Search". Where I'm wrong?
    Tnx for help.

  2. #2
    Regular Contributor
    Join Date
    Sep 2003
    Location
    Finland
    Posts
    99

    Re: Bluetooth - Problem with startInquiry() method

    It seems ok, I get results with that kind of approach except for that I make my own device discoverable as well What so ever, I think it would be wise to put the discovery to it's own thread.

  3. #3
    Regular Contributor
    Join Date
    Mar 2006
    Posts
    124

    Re: Bluetooth - Problem with startInquiry() method

    >> But this code do nothing when i give command "Search".
    It just doesn't locate any devices ?
    Do you get a "Inquiry completed" alert ?
    Did you make sure all other devices are discovery turned on ? - I make this mistake all the time.

  4. #4
    Registered User
    Join Date
    Nov 2004
    Location
    Rome (Italy)
    Posts
    24

    Re: Bluetooth - Problem with startInquiry() method

    The error was simple. I forgot to turn on bluetooth on the phone. I thought that the system would report an indication for activate it.

Similar Threads

  1. Nokia 8910 not working with USB Bluetooth Cards
    By olivieradler in forum General Development Questions
    Replies: 0
    Last Post: 2005-10-05, 10:49
  2. 6230 global problems with Bluetooth
    By asterixmlm in forum General Development Questions
    Replies: 1
    Last Post: 2004-12-10, 17:12
  3. Bluetooth Software + mRouter problem
    By skunkah in forum Bluetooth Technology
    Replies: 0
    Last Post: 2003-12-09, 20:52
  4. Replies: 5
    Last Post: 2003-02-07, 11:25
  5. Problem with Nokia FLA-15 Bluetooth card
    By jpekkola in forum Bluetooth Technology
    Replies: 2
    Last Post: 2002-08-12, 16:42

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •