Advertisement
Guest User

Connect

a guest
Mar 10th, 2014
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.13 KB | None | 0 0
  1. BluetoothAdapter blue = BluetoothAdapter.getDefaultAdapter();
  2. for(int index =0; index<adressAndID.length;index++){
  3.                         // Verbindung herstellen
  4.            
  5.             BluetoothDevice dev = blue.getRemoteDevice(adressAndID[index][0]);
  6.        
  7.             try {
  8.            
  9.                 UUID id1 = UUID
  10.                         .fromString("00001101-0000-1000-8000-00805F9B34FB");
  11.                 if(sock!=null)
  12.                     sock.close();
  13.                 Log.i("Status:", "vor connect");
  14.                         Method m = dev.getClass().getMethod("createRfcommSocket", new Class[] {int.class});                             sock = (BluetoothSocket) m.invoke(dev, 1);
  15.  
  16.                
  17.                 try{
  18.                 sock.connect();
  19.                 }catch(IOException i)
  20.                 {
  21.                     try{
  22.                     sock.connect();
  23.                 }catch(IOException ea)
  24.                 {
  25.                     sock.connect();
  26.                 }
  27.                     }
  28.                
  29.                     Log.i("Status:", "nach connect");
  30.                 in = new Scanner(sock.getInputStream());
  31.                 OutputStream out = sock.getOutputStream();
  32.        
  33.                 // Verbunden
  34.                 String start = "123;";
  35.                 out.write(start.getBytes());
  36.                 //Hier passiert viel Datenverarbeitung
  37.                 publishProgress("Vorgang abgeschlossen.");
  38.                 //Socket schließen
  39.                 in.close();
  40.                 out.close();
  41.                 //out.flush();
  42.                 sock.close();
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement