Advertisement
shashiskills

Untitled

Oct 29th, 2012
1,925
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.24 KB | None | 0 0
  1. package com.kant.remoteBluetooth;
  2.  
  3. import java.io.IOException;
  4. import javax.microedition.io.*;
  5. import javax.bluetooth.*;
  6.  
  7.  
  8. public class WaitThread implements Runnable {
  9.  
  10.  public WaitThread(){}
  11.  
  12.  @Override
  13.  public void run() {  
  14.   waitForConnection();
  15.  }
  16.  
  17.  private void waitForConnection(){
  18.   LocalDevice localdev;
  19.   StreamConnectionNotifier notifier=null;
  20.   StreamConnection conn=null;
  21.   String myServiceName="RemoteNotifier";
  22.   UUID uuid=new UUID("0f2b61c18be240e6ab90e735818da0a7", false);
  23.   System.out.println(uuid.toString());
  24.   String url="btspp://localhost:"+uuid.toString()+";"+"name="+myServiceName ;
  25.   try {
  26.    localdev=LocalDevice.getLocalDevice();  
  27.    localdev.setDiscoverable(DiscoveryAgent.GIAC);  
  28.    notifier=(StreamConnectionNotifier)Connector.open(url);
  29.   } catch (IOException e) {
  30.    // TODO Auto-generated catch block
  31.    e.printStackTrace();
  32.    return;
  33.   }    
  34.   while(true){  
  35.    try {
  36.     System.out.println("Waiting for the Connection");
  37.     conn=notifier.acceptAndOpen();    
  38.     Thread processorThread=new Thread(new ProcessConnectionThread(conn));
  39.     processorThread.start();
  40.    } catch (IOException e) {
  41.     // TODO Auto-generated catch block
  42.     e.printStackTrace();
  43.    }
  44.    
  45.   }
  46.  }
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement