×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    7

    Bluetooth scanning for devices

    Hi,

    New to Java programming on J2ME, I'm trying to create a simple BlueTooth application. I read the tutorial on http://wiki.forum.nokia.com/index.ph...hat_HelloWorld and I think I do understand the needs for BlueTooth communication. My mobile phone (Nokia E50) has JSR82.

    I created the following List, which is created from my main MIDlet after clicking a button (the code in the CommandListener of the MIDlet reads 'new BluetoothDeviceScanner(this);').

    Code:
    package testing;
    
    import java.util.Hashtable;
    
    import javax.bluetooth.BluetoothStateException;
    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.microedition.lcdui.Command;
    import javax.microedition.lcdui.CommandListener;
    import javax.microedition.lcdui.Displayable;
    import javax.microedition.lcdui.List;
    
    public class BluetoothDeviceScanner extends List implements Runnable, CommandListener, DiscoveryListener {
    
    	AD850 midlet;
    	Command cancelScanningCommand, selectCommand, cancelCommand;
    
    	public BluetoothDeviceScanner (AD850 midlet) {
    		super("Scanning...", List.IMPLICIT);
    		this.midlet = midlet;
    
    		cancelScanningCommand = new Command("Cancel", "Cancel scanning", Command.SCREEN, 1);
    		selectCommand = new Command("Select", "Select device", Command.OK, 1);
    		cancelCommand = new Command("Cancel", "Cancel selecting", Command.BACK, 2);
    
    		addCommand(cancelScanningCommand);
    		setCommandListener(this);
    	}
    
    	private Hashtable remoteDevices = new Hashtable();
    
    	public void run () {
    		try {
    			LocalDevice localDevice = LocalDevice.getLocalDevice();
    			DiscoveryAgent discoveryAgent = localDevice.getDiscoveryAgent();
    			discoveryAgent.startInquiry(DiscoveryAgent.LIAC, this);
    		} catch (BluetoothStateException ex) {
    			
    		}
    	}
    
    	public void commandAction(Command command, Displayable displayable) {
    		if (command == cancelScanningCommand) {
    		} else if (command == selectCommand) {
    		} else if (command == cancelCommand) {
    		}
    	}
    
    	int tets = 0;
    	public void deviceDiscovered(RemoteDevice remoteDevice, DeviceClass cod) {
    		setTitle("test="+ tets++);
    		remoteDevices.put(remoteDevice.getBluetoothAddress(), remoteDevice);
    		append(remoteDevice.getBluetoothAddress(), null);
    	}
    
    	public void inquiryCompleted(int arg0) {
    		setTitle("Bluetooth devices");
    	}
    
    	public void servicesDiscovered(int arg0, ServiceRecord[] arg1) {
    	}
    
    	public void serviceSearchCompleted(int arg0, int arg1) {
    	}
    
    }
    The commands don't do anything yet, that's not the problem. The problem is that when I run this on my mobile application, it does not show any device at all, while there both are a MacBook with a discoverable BlueTooth connection, and another Nokia 6300 with a discoverable connection. When I search for BlueTooth devices on y E50, in the normal OS menu, it finds both devices. When I run my MIDlet, it doesn't.

    What am I missing?

    I entered the following line in my jad file:
    Code:
    javax.microedition.io.Connector.bluetooth.client
    But I don't think I need it yet, since I'm only scanning for other devices.

    I have not signed my MIDlet, it does not ask the user (me) if it can access the Networking capabilities of the phone. There might be a problem there, I tried self-signing my application but then the phone won't accept it (certificate error, still trying to resolve this).

    Do I need to resolve the signing problems, or am I missing something else? Thanks for the help in advance!

  2. #2
    Regular Contributor
    Join Date
    Dec 2007
    Posts
    122

    Re: Bluetooth scanning for devices

    Hey,

    Why do you use DiscoveryAgent.LIAC?
    Try to use DiscoveryAgent.GIAC instead.

  3. #3
    Registered User
    Join Date
    Feb 2008
    Posts
    7

    Re: Bluetooth scanning for devices

    Thank you very much for the reply. The devices were indeed generally available (General IAC), not limited (Limited IAC). I guess you should normally do both a LIAC search and a GIAC search, if you want to find all devices available at that point in time?

  4. #4
    Nokia Developer Champion
    Join Date
    Mar 2003
    Posts
    4,105

    Smile

    No, GIAC finds all. I made the same mistake at the beginning. By the way, if you are new to JSR-82, I recommend a book for the start.

  5. #5
    Registered User
    Join Date
    Feb 2008
    Posts
    19

    Re: Bluetooth scanning for devices

    Hi there,

    If you are new to bluetooth progamming have a look at this pdf.http://www.ub.uib.no/elpub/2004/h/41...teroppgave.pdf

  6. #6
    Regular Contributor
    Join Date
    Dec 2007
    Posts
    122

    Re: Bluetooth scanning for devices

    Hey,

    If you are about to buy the book traud suggested than
    take a look at

    At THIS (published at 2/2008)


    It's hasn't published as second edition but it looks like it...

    If you are beginner than this guide will help you

Similar Threads

  1. How To Make The S60 Emulator See My USB Bluetooth Dongle ?
    By Mo7ammed_01 in forum Bluetooth Technology
    Replies: 9
    Last Post: 2009-07-17, 02:33
  2. Replies: 35
    Last Post: 2009-04-11, 14:36
  3. How To Make The S60 Emulator See My USB Bluetooth Dongle ?
    By Mo7ammed_01 in forum Symbian Tools & SDKs
    Replies: 1
    Last Post: 2006-07-25, 00:14
  4. How To Make The S60 Emulator See My USB Bluetooth Dongle ?
    By Mo7ammed_01 in forum Symbian Networking & Messaging (Closed)
    Replies: 1
    Last Post: 2006-07-25, 00:12
  5. Nokia 7650 support Bluetooth audo?
    By ovjo12 in forum Bluetooth Technology
    Replies: 5
    Last Post: 2003-07-17, 18:50

Posting Permissions

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