@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(); } }
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(); }
@Override public void onAccessPointsFound(List<PHAccessPoint> accessPoint) { Log.w(TAG, "Access Points Found. " + accessPoint.size()); if (accessPoint != null && accessPoint.size() > 0) { phHueSDK.getAccessPointsFound().clear(); phHueSDK.getAccessPointsFound().addAll(accessPoint); runOnUiThread( new Runnable() { @Override public void run() { adapter.updateData(phHueSDK.getAccessPointsFound()); } }); HueSharedPreferences prefs2 = HueSharedPreferences.getInstance(AppContext); PHAccessPoint accessPoint2 = (PHAccessPoint) adapter.getItem(0); accessPoint2.setUsername(prefs2.getUsername()); PHBridge connectedBridge = phHueSDK.getSelectedBridge(); if (connectedBridge != null) { String connectedIP = connectedBridge.getResourceCache().getBridgeConfiguration().getIpAddress(); Log.w(TAG, "Connected IP: " + connectedIP); if (connectedIP != null) { // We // are // already // connected // here:- Log.w(TAG, "Connected IP != null"); phHueSDK.disableHeartbeat(connectedBridge); phHueSDK.disconnect(connectedBridge); } } phHueSDK.connect(accessPoint2); } }