I’ve cleared all the errors. However i cannot get the app past “Hello World!”. It does not detect the beacons.
Even when I want to connect through the Estimote App, I need to shake and tap the beacon a number of times before the bluetooth connection is successful.
After connecting the Bluetooth, it takes a very long time to connect to the Estimote cloud. Someone please advise me. This is so frustrating.
Kindly see my code below (I’ve deleted some ID, Token Credentials for security):
package com.example.indoornav;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import com.estimote.mustard.rx_goodness.rx_requirements_wizard.Requirement;
import com.estimote.mustard.rx_goodness.rx_requirements_wizard.RequirementsWizardFactory;
import com.estimote.proximity_sdk.api.EstimoteCloudCredentials;
import com.estimote.proximity_sdk.api.ProximityObserverBuilder;
import com.estimote.proximity_sdk.api.ProximityObserver;
import com.estimote.proximity_sdk.api.ProximityZoneBuilder;
import com.estimote.proximity_sdk.api.ProximityZone;
import com.estimote.proximity_sdk.api.ProximityZoneContext;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import kotlin.Unit;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.functions.Function1;
public class MainActivity extends AppCompatActivity {
private ProximityObserver proximityObserver;
private ProximityObserver ProximityZone;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
EstimoteCloudCredentials cloudCredentials =
new EstimoteCloudCredentials("vuyani-sidinile-s-inda-exx", "ab52d734f0e7884c2fc90e10e52f5");
this.proximityObserver =
new ProximityObserverBuilder(getApplicationContext(), cloudCredentials)
.onError(new Function1<Throwable, Unit>() {
@Override
public Unit invoke(Throwable throwable) {
Log.e("app", "proximity observer error: " + throwable);
return null;
}
})
.withBalancedPowerMode()
.build();
final ProximityZone zone = new ProximityZoneBuilder()
.forTag("Toilet")
.inCustomRange (3.0)
//.inNearRange()
.onEnter(new Function1<ProximityZoneContext, Unit>() {
@Override
public Unit invoke(ProximityZoneContext context) {
String deskOwner = context.getAttachments().get("Location");
Log.d("Toilet", "Welcome to " + deskOwner + "'s desk");
return null;
}
})
.onExit(new Function1<ProximityZoneContext, Unit>() {
@Override
public Unit invoke(ProximityZoneContext context) {
Log.d("Toilet", "Bye bye, come again!");
return null;
}
})
// .build();
.onContextChange(new Function1<Set<? extends ProximityZoneContext>, Unit>() {
@Override
public Unit invoke(Set<? extends ProximityZoneContext> contexts) {
List<String> deskOwners = new ArrayList<>();
for (ProximityZoneContext context : contexts) {
deskOwners.add(context.getAttachments().get("Location"));
}
Log.d("app", "In range of desks: " + deskOwners);
return null;
}
} )
.build();
/* final ProximityZone zone1 = new ProximityZoneBuilder()
.forTag("Room")
.inNearRange()
.onEnter(new Function1<ProximityZoneContext, Unit>() {
@Override
public Unit invoke(ProximityZoneContext context) {
String deskOwner = context.getAttachments().get("Location");
Log.d("app", "Welcome to " + deskOwner + "'s desk");
return null;
}
})
.onExit(new Function1<ProximityZoneContext, Unit>() {
@Override
public Unit invoke(ProximityZoneContext context) {
Log.d("app", "Bye bye, come again!");
return null;
}
})
// .build();
.onContextChange(new Function1<Set<? extends ProximityZoneContext>, Unit>() {
@Override
public Unit invoke(Set<? extends ProximityZoneContext> contexts) {
List<String> deskOwners = new ArrayList<>();
for (ProximityZoneContext context : contexts) {
deskOwners.add(context.getAttachments().get("Location"));
}
Log.d("app", "In range of desks: " + deskOwners);
return null;
}
} )
.build();
final ProximityZone zone2 = new ProximityZoneBuilder()
.forTag("Kitchen")
.inNearRange()
.onEnter(new Function1<ProximityZoneContext, Unit>() {
@Override
public Unit invoke(ProximityZoneContext context) {
String deskOwner = context.getAttachments().get("Location");
Log.d("app", "Welcome to " + deskOwner + "'s desk");
return null;
}
})
.onExit(new Function1<ProximityZoneContext, Unit>() {
@Override
public Unit invoke(ProximityZoneContext context) {
Log.d("app", "Bye bye, come again!");
return null;
}
})
// .build();
.onContextChange(new Function1<Set<? extends ProximityZoneContext>, Unit>() {
@Override
public Unit invoke(Set<? extends ProximityZoneContext> contexts) {
List<String> deskOwners = new ArrayList<>();
for (ProximityZoneContext context : contexts) {
deskOwners.add(context.getAttachments().get("Location"));
}
Log.d("app", "In range of desks: " + deskOwners);
return null;
}
} )
.build();
final ProximityZone zone3 = new ProximityZoneBuilder()
.forTag("Dinning")
.inNearRange()
.onEnter(new Function1<ProximityZoneContext, Unit>() {
@Override
public Unit invoke(ProximityZoneContext context) {
String deskOwner = context.getAttachments().get("Location");
Log.d("app", "Welcome to " + deskOwner + "'s desk");
return null;
}
})
.onExit(new Function1<ProximityZoneContext, Unit>() {
@Override
public Unit invoke(ProximityZoneContext context) {
Log.d("app", "Bye bye, come again!");
return null;
}
})
// .build();
.onContextChange(new Function1<Set<? extends ProximityZoneContext>, Unit>() {
@Override
public Unit invoke(Set<? extends ProximityZoneContext> contexts) {
List<String> deskOwners = new ArrayList<>();
for (ProximityZoneContext context : contexts) {
deskOwners.add(context.getAttachments().get("Location"));
}
Log.d("app", "In range of desks: " + deskOwners);
return null;
}
} )
.build();*/
RequirementsWizardFactory
.createEstimoteRequirementsWizard()
.fulfillRequirements(this,
// onRequirementsFulfilled
new Function0<Unit>() {
@Override public Unit invoke() {
Log.d("app", "requirements fulfilled");
proximityObserver.startObserving(zone);
return null;
}
},
// onRequirementsMissing
new Function1<List<? extends Requirement>, Unit>() {
@Override public Unit invoke(List<? extends Requirement> requirements) {
Log.e("app", "requirements missing: " + requirements);
return null;
}
},
// onError
new Function1<Throwable, Unit>() {
@Override public Unit invoke(Throwable throwable) {
Log.e("app", "requirements error: " + throwable);
return null;
}
});
}
}