[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.8

Bluetooth J2ME - Need practical help with connection example

Asked by idur in Wireless Technologies

Tags: j2me, bluetooth, example

Hello, I am a newbe in J2ME and Bluetooth. I am trying to run an example I found on the net , but not successfull!! And I am getting frustrated because I need to establish a connection via bluetooth to access some data in a Data base!! Which would be the best connection type?? I am lost too because I didn´t find anywhere explaining where do I find the UUID?? neither the host neither the port in btspp://host:port;parameters.
Here is the example I am trying to run!!!
Note that I didn´t change the UUID and host and port because I don´t know!!! Maybe that´s because it´s not working??
When I execute it, it just opens a black screen with nothing. I am testing it on the Series 60 MIDP emulator of NOKIA. Can anyone help me!!!!!

If anyone has a connection via bluetooth with a data base, I would appreciate too!!

BluetoothMIDlet
=============================================================
import java.io.*;
import javax.microedition.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import javax.bluetooth.*;

public class BluetoothMIDlet extends MIDlet implements Runnable, CommandListener {
     
     public BluetoothMIDlet(){}
     
     public void startApp() throws MIDletStateChangeException{
          new Thread(this).start();
     }
     
     public void pauseApp(){}
     public void destroyApp(boolean unconditional){}
     
     public void run(){}
     public void commandAction (Command c, Displayable d){
          notifyDestroyed();}
     
     
}

=============================================================
HelloClient
=============================================================
import java.io.*;
import javax.microedition.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import javax.bluetooth.*;

public class HelloClient extends BluetoothMIDlet {
     
     public void run(){
          Form f = new Form("Cliente");
          f.addCommand(new Command("Sair", Command.EXIT,1));
          f.setCommandListener(this);
          Display.getDisplay(this).setCurrent(f);
         
     try {
          LocalDevice local = LocalDevice.getLocalDevice();
          DiscoveryAgent agent = local.getDiscoveryAgent();
          String connString = agent.selectService(
                    new UUID("86b4d249fb8844d6a756ec265dd1f6a3", false),
                    ServiceRecord.NOAUTHENTICATE_NOENCRYPT, false);
         
          if (connString != null){
               try{
                    StreamConnection conn = (StreamConnection)
                    Connector.open(connString);
                   
                    OutputStream out = conn.openOutputStream();
                    out.write("Esta menssagem é de teste".getBytes());
                    out.close();
                    conn.close();
                   
                    f.append("Menssagem enviada corretamente");
                   
               }
               catch (IOException e){
                    f.append("IOException:" + e.getMessage());
               }
               
          }
          else{
               
               f.append("Não foi possivel localizar o servico");
               
          }
     }catch (BluetoothStateException e){
          f.append("BluetoothStateException: ");
          f.append(e.getMessage());
     }
}
}

=============================================================
HelloServer
==============================================================
import java.io.*;
import javax.microedition.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import javax.bluetooth.*;

public class HelloServer extends BluetoothMIDlet {
     
     public void run(){
         
          Form f = new Form("Servidor");
          f.addCommand(new Command("Sair",Command.EXIT, 1));
          f.setCommandListener(this);
          Display.getDisplay(this).setCurrent(f);
         
          try{
               LocalDevice local = LocalDevice.getLocalDevice();
               if (!local.setDiscoverable(DiscoveryAgent.GIAC)){
                    f.append("Falha ao mudar para modo Discoverable");
                    return;
               }
          StreamConnectionNotifier notifier = (StreamConnectionNotifier)
          Connector.open("btspp://localhost:"+"86b4d249fb8844d6a756ec256dd1f6a3");
         
          StreamConnection conn = notifier.acceptAndOpen();
         
          InputStream in = conn.openInputStream();
          ByteArrayOutputStream out = new ByteArrayOutputStream();
         
          int data;
          while ((data=in.read()) != -1) {
               out.write(data);
          }
         
          f.append(out.toString());
          in.close();
          conn.close();
          notifier.close();
         
          }catch (BluetoothStateException e){
               f.append("BluetoothStateException:"+e.getMessage());
          }catch (IOException e){
               f.append("IOException:"+e.getMessage());
          }
         
     }
}

==============================================================
[+][-]05/10/04 01:43 AM, ID: 11029473Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: Wireless Technologies
Tags: j2me, bluetooth, example
Sign Up Now!
Solution Provided By: jimmack
Participating Experts: 2
Solution Grade: A
 
[+][-]05/07/04 12:43 AM, ID: 11012703Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05/07/04 05:49 AM, ID: 11014112Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05/07/04 06:32 PM, ID: 11019628Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05/07/04 06:33 PM, ID: 11019629Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05/10/04 05:31 AM, ID: 11030497Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05/10/04 06:01 AM, ID: 11030679Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05/19/04 05:34 AM, ID: 11107263Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-92