Esempio n. 1
0
  @Override
  public void onCreate() {
    super.onCreate();
    // Gets an instance of the Hue SDK.
    phHueSDK = PHHueSDK.create();
    // Set the Device Name (name of your app). This will be stored in your bridge whitelist entry.
    phHueSDK.setAppName("QuickStartApp");
    phHueSDK.setDeviceName(Build.MODEL);
    // Register the PHSDKListener to receive callbacks from the bridge.
    phHueSDK.getNotificationManager().registerSDKListener(listener);

    String lastIpAddress = "192.168.0.14";
    String lastUsername = "******";

    // Automatically try to connect to the last connected IP Address.  For multiple bridge support a
    // different implementation is required.
    if (lastIpAddress != null && !lastIpAddress.equals("")) {
      PHAccessPoint lastAccessPoint = new PHAccessPoint();
      lastAccessPoint.setIpAddress(lastIpAddress);
      lastAccessPoint.setUsername(lastUsername);

      if (!phHueSDK.isAccessPointConnected(lastAccessPoint)) {
        phHueSDK.connect(lastAccessPoint);
      }
    } else { // First time use, so perform a bridge search.
      doBridgeSearch();
    }
  }
Esempio n. 2
0
  public void start(BundleContext bundleContext) throws Exception {
    Activator.context = bundleContext;

    ServiceReference<Context> ref = Activator.context.getServiceReference(Context.class);
    AppContext = Activator.context.getService(ref);

    // Gets an instance of the Hue SDK.
    phHueSDK = PHHueSDK.getInstance();

    // Set the Device Name (name of your app). This will be stored in your
    // bridge whitelist entry.
    phHueSDK.setAppName("QuickStartApp");
    phHueSDK.setDeviceName(android.os.Build.MODEL);

    // Register the PHSDKListener to receive callbacks from the bridge.
    phHueSDK.getNotificationManager().registerSDKListener(listener);

    adapter = new AccessPointListAdapter(AppContext, phHueSDK.getAccessPointsFound());

    // Try to automatically connect to the last known bridge. For first time
    // use this will be empty so a bridge search is automatically started.
    prefs = HueSharedPreferences.getInstance(AppContext);
    String lastIpAddress = prefs.getLastConnectedIPAddress();
    String lastUsername = prefs.getUsername();

    // Automatically try to connect to the last connected IP Address. For
    // multiple bridge support a different implementation is required.
    if (lastIpAddress != null && !lastIpAddress.equals("")) {
      PHAccessPoint lastAccessPoint = new PHAccessPoint();
      lastAccessPoint.setIpAddress(lastIpAddress);
      lastAccessPoint.setUsername(lastUsername);

      if (!phHueSDK.isAccessPointConnected(lastAccessPoint)) {
        phHueSDK.connect(lastAccessPoint);
      }
    } else { // First time use, so perform a bridge search.
      doBridgeSearch();
      Log.w(TAG, "Searching for Bridges.");
    }

    myLight = new Light();
  }