コード例 #1
0
ファイル: LinkActivity.java プロジェクト: Q42/hue2
  private void tryIP(final String ip, final String location, int timeout) throws IOException {
    final String description = Networker.doNetwork(location, "GET", "", timeout).getBody();

    // Parsing with RegEx allowed here because the output format is fairly strict
    final String modelName = Util.quickMatch("<modelName>(.*?)</modelName>", description);

    // Check from description if we're dealing with a hue bridge or some other device
    if (modelName.toLowerCase().contains("philips hue bridge")) {
      try {
        final boolean access =
            HueService.userExists(ip, Util.getDeviceIdentifier(LinkActivity.this));
        final String name =
            Util.quickMatch("<friendlyName>(.*?) \\([0-9.]+\\)</friendlyName>", description);
        final String mac = Util.quickMatch("<serialNumber>(.*?)</serialNumber>", description);

        bridgesList.post(
            new Runnable() {
              @Override
              public void run() {
                Bridge b = new Bridge(ip, mac, name, access);
                bridges.add(b);
                bridgesAdapter.add(b);
              }
            });
      } catch (Exception e) {
        // Do nothing, this basically serves as an extra check to see if it's really a hue bridge
        Log.w("hue2", "Found device that identifies as Hue bridge, but isn't one? (" + ip + ")");
        e.printStackTrace();
      }
    }
  }