Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
neeraj_chauhan
Posts: 86
Registered: ‎10-28-2010
My Device: Blackberry Curve, Bold and Strom
My Carrier: Vodafone
Accepted Solution

Data receiving using RFCOMM Protocol from bluetooth enable device

Hi All, 

 

        I want to make an application that recieve data from bluetooth device using RFCOMM Protocol.

 

I am pasting some of my code 

 

StreamConnectionNotifier server = null, server1 = null, server2 = null;

 

UiApplication.getUiApplication().invokeLater(new Runnable() 
 {
 public void run() 
 {
 try
 {
 System.out.println("1"); 
            String url = "btspp://localhost:11111111111111111111111111111111;name=name";
            System.out.println("2"); 
            server = (StreamConnectionNotifier) Connector.open(url, Connector.READ_WRITE, false);
            System.out.println("3"); 
        }
 catch(Exception e)
        {
 System.out.println("4 "+e.toString()); 
        }
 try
 {
 System.out.println("111"); 
            String url = "btspp://localhost:" + new UUID(0x1101).toString()+";name=SampleServer";
            System.out.println("222"); 
            server1 = (StreamConnectionNotifier) Connector.open(url, Connector.READ_WRITE, false);
            System.out.println("333"); 
        }
 catch(Exception e)
        {
 System.out.println("444 "+e.toString()); 
        }
 try
 {
 UUID uuid = new UUID("1101", true);
 System.out.println("1111"); 
            String url = "btspp://localhost:"+uuid+";name=File Transfert Agent"+ ";authenticate=false;master=false;encrypt=false";
            System.out.println("2222"); 
            server2 = (StreamConnectionNotifier) Connector.open(url, Connector.READ_WRITE, false);
            System.out.println("3333"); 
        }
 catch(Exception e)
        {
 System.out.println("4444 "+e.toString()); 
        }
 try
 {
 UUID uuid = new UUID("0003", true);
 System.out.println("11111"); 
            String url = "btspp://localhost:"+uuid+";name=File Transfert Agent"+ ";authenticate=false;master=false;encrypt=false";
            System.out.println("22222"); 
           server2 = (StreamConnectionNotifier) Connector.open(url, Connector.READ_WRITE, false);
           System.out.println("33333"); 
       }
catch(Exception e)
       {
System.out.println("44444 "+e.toString()); 
       }
}
});
//        Waiting for connection and receiving data:
if(server1 != null)
{
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() 
{
while(true)
       {
        System.out.println("5"); 
           StreamConnection connection = null;
           try
           {
            System.out.println("6"); 
               connection = server.acceptAndOpen();
               System.out.println("61"); 
//                progressBar.open();
               
               DataInputStream dis = connection.openDataInputStream();
               DataOutputStream dos = connection.openDataOutputStream();   
               try
               {
                System.out.println("11"); 
                byte[] buffer = new byte[ 1024 ];
                System.out.println("12"); 
                   int readBytes = dis.read(buffer);
                   System.out.println("13"); 
                   String receivedMessage = new String(buffer, 0, readBytes);
                   System.out.println("14"); 
                   System.out.println("15"); 
                   System.out.println("[CLIENT] Message received: " + receivedMessage);  
                   System.out.println("16"); 
               }
               catch (Exception e)
               {
                System.out.println("1 Error "+e.toString()); 
}
              
               System.out.println("7"); 
               dos.close();
               dis.close();   
           }                                  
           catch(Exception e1)
           {
            System.out.println("8 "+e1.toString()); 
           }
           finally
           {                                       
               if(connection != null){
                   try {                            
                       connection.close();
                   } catch(Exception ignore) {
                       }
               }
               if(server != null){
                   try {                            
                       server.close();
                   } catch(Exception ignore) {
                       }
               }
               connection = null;    
               server = null;                                                                      
           }
       }
}
});

 

 

 

and OUTPUT is like this

 

1

2

CMM: RemoteHealth-1(2648) no sig from 0x33

4 java.lang.RuntimeException: blocking operation not permitted on event dispatch thread

111

222

444 java.lang.RuntimeException: blocking operation not permitted on event dispatch thread

1111

2222

4444 java.lang.RuntimeException: blocking operation not permitted on event dispatch thread

11111

22222

44444 java.lang.RuntimeException: blocking operation not permitted on event dispatch thread

 

 

 

 

java.lang.RuntimeException: blocking operation not permitted on event dispatch thread

 

Can somebody know why I am getting this error? i Used all the possible ways. I am always getting this error.

 

 

Thanks & Regards
Neeraj Chauhan
Please use plain text.
Developer
neeraj_chauhan
Posts: 86
Registered: ‎10-28-2010
My Device: Blackberry Curve, Bold and Strom
My Carrier: Vodafone

Re: Data receiving using RFCOMM Protocol from bluetooth enable device

HI All,

 

Can some body having any idea or sample code to recieve data using RFCOMM Protocol for Bluetooth. I am able to search an bluetooth enable device and also connect with it.

 

     And ther eis one more problem I only one particlar device is not forming any kind of link(SPP Url link, OPP Url LInk, etc) for bluetooth.

 

     But I can check that this device is correct because I am able to receive data from this device to my computer by checking the connection port and open that port.

 

 

 

Thanks & Regards
Neeraj Chauhan
Please use plain text.
Developer
neeraj_chauhan
Posts: 86
Registered: ‎10-28-2010
My Device: Blackberry Curve, Bold and Strom
My Carrier: Vodafone

Re: Data receiving using RFCOMM Protocol from bluetooth enable device

Hi all,

 

          My problem is resolved. I am able to achieve this in Torch 9800 but it's not working on Curve 8520. So, I am closing my thread. 

 

 

If anyone need any kind of help regarding Bluetooth. Please let me know. 

 

:Flowers:

Thanks & Regards
Neeraj Chauhan
Please use plain text.
Developer
shahumang8
Posts: 597
Registered: ‎08-09-2010
My Device: Not Specified

Re: Data receiving using RFCOMM Protocol from bluetooth enable device

Hello,

 

 Today i check this code and i build one test app but they throws same error when you got 8520.So porvide me any solution.

 

 I check this code into 9800 BlackBerry.

 

Thanks.

Please use plain text.
Super Contributor
lyon819
Posts: 253
Registered: ‎08-19-2010
My Device: BB10, Playbook, 9900, 9800, 9700, 9550, 9530, 9500, 8700.
My Carrier: TT

Re: Data receiving using RFCOMM Protocol from bluetooth enable device

Could you share how do you solve the issue??

 

I also try to use RFCOMM to receive data by bluetooth.

 

 

 

-Fight with BB10
Please use plain text.
New Contributor
shyamsathan
Posts: 2
Registered: ‎12-17-2012
My Device: curve, bold
My Carrier: airtel

Re: Data receiving using RFCOMM Protocol from bluetooth enable device

Hi Neeraj,

 

I am new to BB development. I am facing problem with bluetooth head set , while i am searching for service i am getting service record nopt found response code. i already paired the headset with my BB device.

 

UUID auuid[] = new UUID[1];

auuid[0] = new UUID("0000110100001000800000805F9B34FB",false);
 int ai[] = {0x0100};
mDiscoveryAgent.searchServices(ai, auuid,rmDeviceList[0],BTInquiryThread.this);

 

after this, i am getting response code 4 (DiscoveryListener.SERVICE_SEARCH_NO_RECORDS). Can you help on this.

 

Thanks and regards

Shyam sathyan

Thanks & Regards
Shyam Sathyan
Please use plain text.
New Contributor
shyamsathan
Posts: 2
Registered: ‎12-17-2012
My Device: curve, bold
My Carrier: airtel

Re: Data receiving using RFCOMM Protocol from bluetooth enable device

Issue solved ...:smileyhappy:

Thanks & Regards
Shyam Sathyan
Please use plain text.