⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bluetoothclient.java

📁 Java编写的蓝牙手机遥控器
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                    break;
                  this.own.informError("Bluetooth direct connection failed!");
                  this.action = 0;
                  this.state = 0;
                }
                this.state = 2;
                this.parent.connectSuccess();
                this.action = 0;
              }
              label457: this.own.informInformation("A connection to a Bluetooth computer has never been made!");
              this.state = 0;
            }
        BluetoothRemoteControl.debug("INCOMING_CONNECTION");
        this.state = 2;
        this.action = 0;
        this.conn = this.serverConn;
        try
        {
          this.out = this.conn.openOutputStream();
        }
        catch (IOException localIOException2)
        {
          while (true)
          {
            try
            {
              this.conn.close();
            }
            catch (IOException localIOException3)
            {
            }
            this.action = 0;
            this.state = 0;
            this.own.informError("Bluetooth incomming connection failed! Could not create outputStream");
          }
        }
        this.server = new BluetoothClient.BluetoothServer(this);
        this.parent.connectSuccess();
      }
      BluetoothRemoteControl.debugError("State error");
    }
    try
    {
      label586: this.conn.close();
    }
    catch (IOException localIOException1)
    {
    }
  }

  private String searchDevices()
  {
    String str1;
    this.devices.removeAllElements();
    Object localObject1 = "";
    Vector localVector = new Vector();
    try
    {
      this.discoveryAgent.startInquiry(10390323, this);
    }
    catch (BluetoothStateException localBluetoothStateException)
    {
      str1 = "Can't start inquiry now: " + localBluetoothStateException;
      return str1;
    }
    try
    {
      super.wait();
      BluetoothRemoteControl.debug("searchDevices");
    }
    catch (InterruptedException localInterruptedException)
    {
      str1 = "Unexpected interuption 2: " + localInterruptedException;
      return str1;
    }
    if (this.isClosed)
    {
      str1 = "User cancel!";
      return str1;
    }
    if (this.userCancel)
    {
      str1 = "User cancel!";
      return str1;
    }
    switch (this.discType)
    {
    case 5:
      this.devices.removeAllElements();
      BluetoothRemoteControl.debug("INQUIRY_TERMINATED");
      str1 = "INQUIRY_TERMINATED...";
      localObject1 = str1;
      break;
    case 0:
    case 7:
      localObject1 = "";
      BluetoothRemoteControl.debug("INQUIRY_COMPLETED");
      if (this.devices.size() == 0)
        break label307:
      BluetoothRemoteControl.debug("Devices in range!");
      for (int i = 0; i < this.devices.size(); ++i)
        try
        {
          RemoteDevice localRemoteDevice = (RemoteDevice)this.devices.elementAt(i);
          String str2 = localRemoteDevice.getFriendlyName(false);
          localVector.addElement(str2);
        }
        catch (IOException localIOException)
        {
          localVector.addElement("Computer");
        }
      this.parent.showDevicesFound(localVector);
      break;
    default:
      str1 = "System error:  Unexpected device discovery code: " + this.discType;
      localObject1 = str1;
    }
    label307: BluetoothRemoteControl.debug("Inquiry end!");
    return ((String)localObject1);
  }

  // ERROR //
  private boolean searchServices()
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 9	BluetoothClient:records	Ljava/util/Vector;
    //   4: invokevirtual 98	java/util/Vector:removeAllElements	()V
    //   7: aload_0
    //   8: iconst_1
    //   9: newarray int
    //   11: putfield 41	BluetoothClient:searchIDs	[I
    //   14: ldc 117
    //   16: invokestatic 61	BluetoothRemoteControl:debug	(Ljava/lang/String;)V
    //   19: iconst_0
    //   20: istore_1
    //   21: iload_1
    //   22: iconst_2
    //   23: if_icmpge +112 -> 135
    //   26: aload_0
    //   27: getfield 8	BluetoothClient:devices	Ljava/util/Vector;
    //   30: aload_0
    //   31: getfield 45	BluetoothClient:deviceToConnect	I
    //   34: invokevirtual 110	java/util/Vector:elementAt	(I)Ljava/lang/Object;
    //   37: checkcast 111	javax/bluetooth/RemoteDevice
    //   40: astore_2
    //   41: ldc 118
    //   43: invokestatic 61	BluetoothRemoteControl:debug	(Ljava/lang/String;)V
    //   46: aload_0
    //   47: getfield 41	BluetoothClient:searchIDs	[I
    //   50: iconst_0
    //   51: aload_0
    //   52: getfield 20	BluetoothClient:discoveryAgent	Ljavax/bluetooth/DiscoveryAgent;
    //   55: aconst_null
    //   56: aload_0
    //   57: getfield 31	BluetoothClient:uuidSet	[Ljavax/bluetooth/UUID;
    //   60: aload_2
    //   61: aload_0
    //   62: invokevirtual 119	javax/bluetooth/DiscoveryAgent:searchServices	([I[Ljavax/bluetooth/UUID;Ljavax/bluetooth/RemoteDevice;Ljavax/bluetooth/DiscoveryListener;)I
    //   65: iastore
    //   66: ldc 120
    //   68: invokestatic 61	BluetoothRemoteControl:debug	(Ljava/lang/String;)V
    //   71: goto +64 -> 135
    //   74: astore_3
    //   75: new 22	java/lang/StringBuffer
    //   78: dup
    //   79: invokespecial 23	java/lang/StringBuffer:<init>	()V
    //   82: ldc 121
    //   84: invokevirtual 25	java/lang/StringBuffer:append	(Ljava/lang/String;)Ljava/lang/StringBuffer;
    //   87: aload_2
    //   88: invokevirtual 122	javax/bluetooth/RemoteDevice:getBluetoothAddress	()Ljava/lang/String;
    //   91: invokevirtual 25	java/lang/StringBuffer:append	(Ljava/lang/String;)Ljava/lang/StringBuffer;
    //   94: ldc 123
    //   96: invokevirtual 25	java/lang/StringBuffer:append	(Ljava/lang/String;)Ljava/lang/StringBuffer;
    //   99: aload_3
    //   100: invokevirtual 26	java/lang/StringBuffer:append	(Ljava/lang/Object;)Ljava/lang/StringBuffer;
    //   103: invokevirtual 27	java/lang/StringBuffer:toString	()Ljava/lang/String;
    //   106: invokestatic 28	BluetoothRemoteControl:debugError	(Ljava/lang/String;)V
    //   109: iconst_0
    //   110: istore 4
    //   112: iload 4
    //   114: ireturn
    //   115: astore_3
    //   116: ldc 124
    //   118: invokestatic 28	BluetoothRemoteControl:debugError	(Ljava/lang/String;)V
    //   121: goto +8 -> 129
    //   124: astore 5
    //   126: aload 5
    //   128: athrow
    //   129: iinc 1 1
    //   132: goto -111 -> 21
    //   135: aload_0
    //   136: invokevirtual 62	java/lang/Object:wait	()V
    //   139: goto +35 -> 174
    //   142: astore_2
    //   143: new 22	java/lang/StringBuffer
    //   146: dup
    //   147: invokespecial 23	java/lang/StringBuffer:<init>	()V
    //   150: ldc 125
    //   152: invokevirtual 25	java/lang/StringBuffer:append	(Ljava/lang/String;)Ljava/lang/StringBuffer;
    //   155: aload_2
    //   156: invokevirtual 26	java/lang/StringBuffer:append	(Ljava/lang/Object;)Ljava/lang/StringBuffer;
    //   159: invokevirtual 27	java/lang/StringBuffer:toString	()Ljava/lang/String;
    //   162: invokestatic 28	BluetoothRemoteControl:debugError	(Ljava/lang/String;)V
    //   165: iconst_0
    //   166: istore_3
    //   167: iload_3
    //   168: ireturn
    //   169: astore 6
    //   171: aload 6
    //   173: athrow
    //   174: ldc 126
    //   176: invokestatic 61	BluetoothRemoteControl:debug	(Ljava/lang/String;)V
    //   179: aload_0
    //   180: getfield 51	BluetoothClient:isClosed	Z
    //   183: ifeq +5 -> 188
    //   186: iconst_0
    //   187: ireturn
    //   188: ldc 127
    //   190: invokestatic 61	BluetoothRemoteControl:debug	(Ljava/lang/String;)V
    //   193: iconst_1
    //   194: ireturn
    //
    // Exception table:
    //   from	to	target	type
    //   41	71	74	javax/bluetooth/BluetoothStateException
    //   41	71	115	java/lang/Error
    //   41	71	124	finally
    //   74	112	124	finally
    //   115	121	124	finally
    //   124	126	124	finally
    //   135	139	142	java/lang/InterruptedException
    //   135	139	169	finally
    //   142	167	169	finally
    //   169	171	169	finally
  }

  private boolean connectToBlutoothDevice(boolean paramBoolean)
  {
    ServiceRecord localServiceRecord;
    String str = null;
    BluetoothRemoteControl.debug("connectToBlutoothDevice");
    try
    {
      if (!(paramBoolean))
      {
        localServiceRecord = (ServiceRecord)this.records.firstElement();
        str = localServiceRecord.getConnectionURL(0, false);
        storeRecord(str);
        this.conn = ((StreamConnection)Connector.open(str));
      }
      else
      {
        str = readRecord();
        BluetoothRemoteControl.debug(str);
        this.conn = ((StreamConnection)Connector.open(str));
      }
    }
    catch (IOException localIOException1)
    {
      try
      {
        if (!(paramBoolean))
        {
          localServiceRecord = (ServiceRecord)this.records.firstElement();
          str = localServiceRecord.getConnectionURL(0, false);
          storeRecord(str);
          this.conn = ((StreamConnection)Connector.open(str));
        }
        else
        {
          str = readRecord();
          BluetoothRemoteControl.debug(str);
          this.conn = ((StreamConnection)Connector.open(str));
        }
      }
      catch (IOException localIOException3)
      {
        BluetoothRemoteControl.debugError("Connection failed! 1");
        int j = 0;
        return j;
      }
    }
    try
    {
      BluetoothRemoteControl.debug("conn.openOutputStream()");
      this.out = this.conn.openOutputStream();
    }
    catch (IOException localIOException2)
    {
      try
      {
        this.conn.close();
      }
      catch (IOException localIOException4)
      {
      }
      this.own.informError("Failed to open OutputStream!");
      int i = 0;
      return i;
    }
    this.server = new BluetoothClient.BluetoothServer(this);
    BluetoothRemoteControl.debug("connectToBlutoothDevice end");
    return true;
  }

  public void reConnect()
  {
    readRecord();
    if (this.state == 0)
    {
      this.state = 4;
      requestSearch();
    }
    else
    {
      this.own.informInformation("Local bluetooth device is busy!");
    }
  }

  private void disconnectedByRemote()
  {
    try
    {
      this.out.close();
    }
    catch (IOException localIOException1)
    {
    }
    try
    {
      this.conn.close();
    }
    catch (IOException localIOException2)
    {
    }
    this.state = 0;
  }

  public void disconnect()
  {
    this.server.destroy();
    try
    {
      this.out.close();
    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -