Problems with Connect to the beacon

Hi guys,
I have a problem with connecting to the beacon. I followed your guide I did the following code:

My OnCreate:

public class BeaconSetting extends AppCompatActivity
{
private ConfigurableDevicesScanner deviceScanner;
private DeviceConnectionProvider connectionProvider;
public ConfigurableDevice deviceToConnectTo= null;

@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
EstimoteSDK.initialize(getApplicationContext(), “xxxxxxxx”, “xxxxxxxxxxxxxxxxxxxxxxxx”);
setContentView(R.layout.activity_beacon_setting);

 connectionProvider = new DeviceConnectionProvider(this);
 connectionProvider.connectToService(new DeviceConnectionProvider.ConnectionProviderCallback()
{
    @Override
    public void onConnectedToService()
    {
        DeviceConnection connection = connectionProvider.getConnection(deviceToConnectTo);
        connection.connect(new DeviceConnectionCallback()
            {
            @Override
            public void onConnected() {
                Log.d("DeviceConnection", "Connected");
            }

            @Override
            public void onDisconnected() {
                Log.d("DeviceConnection", "Disconnected");
            }

            @Override
            public void onConnectionFailed(DeviceConnectionException exception) {
                Log.d("DeviceConnection",
                        "Connection failed with error: " + exception.toString());
             }
          });
       }
   });
}

My onResume

@Override
protected void onResume()
{

super.onResume();
deviceScanner = new ConfigurableDevicesScanner(this);
deviceScanner.setOwnDevicesFiltering(false);
deviceScanner.setDeviceTypes(DeviceType.LOCATION_BEACON);
deviceScanner.scanForDevices(new ConfigurableDevicesScanner.ScannerCallback()
{
  @Override
  public void onDevicesFound(List<ConfigurableDevicesScanner.ScanResultItem> devices) 
  {  
     String deviceIdentifier = "xxxxxxxxxxxxxxxxxxxxxxxxxxx";

    for (ConfigurableDevicesScanner.ScanResultItem item : devices)
    {
        if (item.device.deviceId.toHexString().equals(deviceIdentifier))
        {
            deviceToConnectTo =item.device;
            Toast.makeText(BeaconSetting.this, ""+ deviceToConnectTo, Toast.LENGTH_LONG).show();
            break;
         }
     }
    }
});
}

My onPause

@Override
protected void onPause()
{
deviceScanner.stopScanning();
super.onPause();
}

My onDestroy

@Override
protected void onDestroy()
{
connectionProvider.destroy();
super.onDestroy();
}

My deviceToConnectTo variable within the onResume stores the desired
beacon while in my onCreate when it is passed to the connectionProvider
takes the value null.
How can I use my ConfigurableDevice object in connectionProvider?

Please update your SDK, now connecting to beacons changed a little bit.
There is no ConfigurableDevicesScanner, you are supposed to use BeaconManager to look for configurable devices.
Latest guide is on GitHub: https://github.com/Estimote/Android-SDK/blob/master/Docs/DOC_deviceConnection.md
Update to Developer Portal is coming soon.

This API was intended to use in two different activities. In first you scanned for devices, then user selected one of them, it was put inside intent and passed to seconds activity where connection was being made.

If you want to do those two things in single activity, you should:

  • connect to DeviceConnectionProvider
  • inside onConnectedToService connect to BeaconManager
  • after BeaconManager started in onServiceReady configure ConfigurableDevicesListener and start scanning.

This way you connect to two services one after another and race condition between two asynchronous callbacks as in code above.