×

Discussion Board

Results 1 to 13 of 13

Hybrid View

  1. #1
    Registered User
    Join Date
    Jan 2005
    Location
    Helsinki, Finland
    Posts
    257

    Question Bluetooth midlet client to find a service by service name?

    Hi,

    I have a Bluetooth server which advertise a service in RFCOMM with a service name as "my_service" nothing more than this. I have to connect to this service by using a midlet (j2me) and send just a string.

    I'm new in Java world. I found lots of bluetooth example client/server from net. All of them the the same concept is having a UUID and attributes. So far no API or example of connecting to by service name. Only as follow:-

    DiscoveryAgent.searchServices(int[] attrSet,UUID[] uuidSet,RemoteDevice btDev, DiscoveryListener discListener);

    Is there any way/API to discover bluetooth service by name?
    Do it now! Today will be yesterday tomorrow - MadSum

  2. #2
    Nokia Developer Expert
    Join Date
    Aug 2011
    Posts
    555

    Re: Bluetooth midlet client to find a service by service name?

    Hi,

    Unfortunately, the UUID is needed in the Service Discovery Process so you cannot skip it.

    Take a look at this link for more info:

    http://library.developer.nokia.com/i...58ED8BA4D.html

    A very simple example code, that does exactly what you need (connect to a server and send a message) can be found here:

    http://www.developer.nokia.com/Commu...ice_in_Java_ME
    http://www.developer.nokia.com/Commu...ces_in_Java_ME

    Is there a reason why you need to connect to a service by name? You may consider the UUID as a very long "name" for your service.

  3. #3
    Registered User
    Join Date
    Jan 2005
    Location
    Helsinki, Finland
    Posts
    257

    Re: Bluetooth midlet client to find a service by service name?

    I found these example before. But the problem is that:-

    Server advertise the service name as by connServiceName. But client never uses any service name to discover the service. Client only use UUID.

    The server is already made in such a way using qt c++ api. There are other client in different platform such as memo, meego, symbain, ios, etc having bluetooth interface and api. Thus I would like to add j2me as a supported platform as well. Just wondering is it possible at all to discover service just by service name in j2me?
    Do it now! Today will be yesterday tomorrow - MadSum

  4. #4
    Nokia Developer Expert
    Join Date
    Aug 2011
    Posts
    555

    Re: Bluetooth midlet client to find a service by service name?

    Yes that is correct,

    In the example, the client uses the UUID in order to identify the service running on the server. It is of course possible for the client to retrieve the Service name (if one has been defined on server's side), while performing the Service Discovery operation, by using the ServiceName attribute (0x100). To do that you need to provide the attribute as argument in the searchServices method, you need to retrieve all the attributes and their IDs for a given Service Record and then you need to retrieve the value of the Service Name attribute.

    I have added a Service Name retrieval in the examples below, so if you take a look at the examples now, you will see how to do it.

  5. #5
    Registered User
    Join Date
    Jan 2005
    Location
    Helsinki, Finland
    Posts
    257

    Re: Bluetooth midlet client to find a service by service name?

    Quote Originally Posted by skalogir View Post
    Yes that is correct,

    In the example, the client uses the UUID in order to identify the service running on the server. It is of course possible for the client to retrieve the Service name (if one has been defined on server's side), while performing the Service Discovery operation, by using the ServiceName attribute (0x100). To do that you need to provide the attribute as argument in the searchServices method, you need to retrieve all the attributes and their IDs for a given Service Record and then you need to retrieve the value of the Service Name attribute.

    I have added a Service Name retrieval in the examples below, so if you take a look at the examples now, you will see how to do it.
    Actually I tried ServiceName attribute (0x100) this way didn't succeed. After several failure try I gave up. I guess u forgot to paste the example code. Could you please provide the example. Thanks in advance.
    Do it now! Today will be yesterday tomorrow - MadSum

  6. #6
    Nokia Developer Expert
    Join Date
    Aug 2011
    Posts
    555

    Re: Bluetooth midlet client to find a service by service name?

    I am not using the name anywhere, therefore I put the code in comments, so that it is visible how one can retrieve the service name. You just need to uncomment the three lines in the servicesDiscovered method in this example:

    http://www.developer.nokia.com/Commu...ces_in_Java_ME

    The ServiceName DataElement in the above example can be used for the retrieval of the Service name by calling the getValue() method on the DataElement object and by converting the value to String.
    This should return "My Spp-service" which is the name of the Service defined on the server.

    Please also make sure that you run the server part on a separate device:
    http://www.developer.nokia.com/Commu...ice_in_Java_ME

  7. #7
    Registered User
    Join Date
    Jan 2005
    Location
    Helsinki, Finland
    Posts
    257

    Re: Bluetooth midlet client to find a service by service name?

    There is no data type defined as ServiceRecord.ID_ServiceID and ServiceRecord.ID_ServiceName. So simply uncomment those line is not gonna work/compile. Also there is no DataElement type defined on the given example. As I mentioned I'm pretty new in the Java world. Instead of verbal explanation some example compileable code would really help me a lot.

    int[] attributesList = new int[2];
    attributesList[0] = ServiceRecord.ID_ServiceID;
    attributesList[1] = ServiceRecord.ID_ServiceName;
    Do it now! Today will be yesterday tomorrow - MadSum

  8. #8
    Nokia Developer Expert
    Join Date
    Aug 2011
    Posts
    555

    Re: Bluetooth midlet client to find a service by service name?

    Client:
    1. Clean your browser's cache/history and temporary files.
    2. Go to http://www.developer.nokia.com/Commu...ces_in_Java_ME
    3. On the Article Metadata section of the page, on the right, there is link to source file. Download the zip file.
    4. Unzip it to your local drive.
    5. Open the .java file and search for the following text: "DataElement ServiceName" (without the quotes). This is the part of the code that shows you how to retrieve the service's name.
    6. Compile the code or just use the already compiled .jar and .jad files in the zip, to install the application on your phone.

    Server:
    7. Go to http://www.developer.nokia.com/Commu...ice_in_Java_ME
    8. At the bottom of this page you can find a similar zip file. Download it and unzip it to your local drive.
    9. Either compile the source code or use directly the executables to install the server application on a separate device.

    After you have installed both server and client applications on different devices:
    1. Open the server application.
    2. Select Start
    3. Open the client application.
    4. Select Options>DevicesDiscovery
    5. Wait until you get a notification that "Device Discovering Complete"
    6. Select from the list of found devices the device where the server application is running.
    7. Select Options>DiscoverServices.

    The last action should give you some notifications on the screen including the service's name as it has been defined on the server.

    Please note, that you still need to specify a UUID for the service discovery and you cannot rely only on the service's name.

  9. #9
    Registered User
    Join Date
    Jan 2005
    Location
    Helsinki, Finland
    Posts
    257

    Re: Bluetooth midlet client to find a service by service name?

    Thanks a lot! I got it working ok.

    Just another novice question. In code there is "printToForm("The Service name is: "+ServiceName.getValue())" "DataElement.getValue()" which returns object. Thus I can see service name as "java.util.vector$1@3c60cd14c". I tried to convert object to string as String str = (ServiceName.getValue()).toString(); It doesn't convert. So how to convert object to string. So that I could see the service name correctly.
    Do it now! Today will be yesterday tomorrow - MadSum

  10. #10
    Nokia Developer Expert
    Join Date
    Aug 2011
    Posts
    555

    Re: Bluetooth midlet client to find a service by service name?

    You should actually be able to see the service name in plain string. What is the device you are testing on, and the software version running on the device (You can see that by pressing *#0000#)?

  11. #11
    Registered User
    Join Date
    Jan 2005
    Location
    Helsinki, Finland
    Posts
    257

    Re: Bluetooth midlet client to find a service by service name?

    Nokia 5230.
    Software version V 40.0.003
    date: 09.12.2010

    custom version 40.0.003.c02.01
    date: 09.12.2010

    Nokia e71
    510.21.009
    19-03-2011
    rm-346

    for Nokia e71 service name is "java.util.VactorEnumeratgor@15dc1cbe"
    for Nokia 5230 service name is "java.util.vector$1@3c60cd14c"
    Do it now! Today will be yesterday tomorrow - MadSum

  12. #12
    Nokia Developer Expert
    Join Date
    Aug 2011
    Posts
    555

    Re: Bluetooth midlet client to find a service by service name?

    I have added a more generic Service Discovery, where an iteration through all of the retrieved attributes is made. It seems that the attribute indexes are different in your case. This is now corrected.

    Can you please try again to follow the steps below (make sure to clean your browser's cache so that you get the latest version).

  13. #13
    Registered User
    Join Date
    Jan 2005
    Location
    Helsinki, Finland
    Posts
    257

    Re: Bluetooth midlet client to find a service by service name?

    Yes, it is working correctly now.

    So far I didn't get any response from any other forum or even here u r the only one who real show me all the way. I might get further problem in my actual development of the project. I'm not sure in such case should I open new thread and knock u each time to get ur attention.

    Thank you very very much.
    Do it now! Today will be yesterday tomorrow - MadSum

Similar Threads

  1. Service Framework can't find service plugins
    By chenpeiwen in forum [Archived] Qt Mobility Project
    Replies: 1
    Last Post: 2010-03-10, 07:34
  2. Error at the time of Running Client Midlet for accessing Web Service
    By anupdesai1248 in forum Mobile Java General
    Replies: 12
    Last Post: 2009-08-29, 13:08
  3. My cellphone can't find a service in a bluetooth module
    By hugoq in forum Mobile Java Networking & Messaging & Security
    Replies: 2
    Last Post: 2009-08-11, 20:11
  4. Cannot find where the issue is, Bluetooth service discovery
    By newbietoprofessional in forum Mobile Java Networking & Messaging & Security
    Replies: 3
    Last Post: 2008-07-14, 16:39
  5. Cannot find bluetooth service
    By coffeecry825 in forum Mobile Java General
    Replies: 1
    Last Post: 2006-05-20, 17:00

Posting Permissions

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