Proximity App via SDK
Steps
- Prerequisites
- 1 x computer with android studio
- 1 x Android phone with android 5.0
- 1 x Estimote proximity beacon
- Proximity Beacon Setup
- Download estimote app
- Configure ->find beacons -> login -> enable Estimote monitoring
- Download estimote app
- Download Estimote Example App
- https://github.com/Estimote/Android-Proximity-SDK
- Import SDK into Android Studio
- Estimote will automatically import their basic Methods and app interface
- Add Permissions to build.Gradle
- In your build.gradle tab add estimote SDK lines that will grab your necessary permissions
- general-SDK
- perimeter-SDK
- Estimote-mustard
- In your build.gradle tab add estimote SDK lines that will grab your necessary permissions
- Add Proximity Observer to Activity class
- Set up Cloud Credentials inside generated onCreate method
- Credentials will give your app the ability recognize specific beacon ID’s
- Add Proximity Observer Object
- To add the Proximity Object you will need to create a builder inside your onCreate method underneath your Credentials
- Set up Cloud Credentials inside generated onCreate method
- Define Proximity Zones
- Log onto Estimote app and select your beacon, in edit, select beacon attachments
- In beacon attachments define location and ownership of beacon
- Creating Proximity Zone Objects
- Add a Proximity Zone beneath your Proximity Observer Builder
- If desired, it is possible to create multiple zones for different beacons
- Add a Proximity Zone beneath your Proximity Observer Builder
- Log onto Estimote app and select your beacon, in edit, select beacon attachments
- Start Proximity Observing
- Requires location permissions in your build.gradle
- ACCESS_FINE_LOCATION
- At the end of your onCreate Method define a new proximity zone “proximityObserver”
- Proximity observer will have 3 cases
- Requirements fulfilled - proximityObserver.start
- Requirements missing - log error message
- Requirements error - log error message
- Each case will return null.
- Proximity observer will have 3 cases
- Requires location permissions in your build.gradle
- POST Requests
- You will need to create a post request so your app can talk to Amazon Web Services
- Need two instances of request
- 1st POST request will be under your proximity observer
- A generic POST template found online works perfectly
- Paste code in and modify parameters ensuring that they match up with the AWS side
- Username
- Password
- beaconID
- Open
- Set open to TRUE or 1
- 2nd POST request will be entered beneath onExit action
- 1st POST request will be under your proximity observer
- A generic POST template found online works perfectly
- Paste code in and modify parameters ensuring that they match up with the AWS side
- Username
- Password
- beaconID
- Open
- Set open to False or 0
- 1st POST request will be under your proximity observer
- 1st POST request will be under your proximity observer
You should be good to go!
Example Code for Each Part
Gradle Build Permissions: [ implementation 'com.estimote:proximity-sdk:0.2.+' implementation 'com.estimote:mustard:0.+' implementation 'com.estimote:sdk:1.2.0' ] Cloud Credentials: CloudCredentials cloudCredentials = new EstimoteCloudCredentials("Token", "BeaconID");
Proximity Object Builder this.proximityObserver =
new ProximityObserverBuilder(getApplicationContext(), cloudCredentials) .withOnErrorAction(new Function1<Throwable, Unit>() { @Override public Unit invoke(Throwable throwable) { Log.e("app", "proximity observer error: " + throwable); return null; } }) .withBalancedPowerMode() .build();
Proximity Zone ProximityZone zone1 = this.proximityObserver.zoneBuilder()
.forAttachmentKeyAndValue("lock", "0") .inCustomRange(1.0) .withOnEnterAction(new Function1<ProximityAttachment, Unit>() { @Override public Unit invoke(ProximityAttachment attachment) { Log.d("app", "Detected Lock 0 Beacon"); showNotification("Detected Beacon", "Lock 0");
final TextView mTextView = (TextView) findViewById(R.id.text);
Proximity Observer this.proximityObserver.addProximityZone(zone1);
RequirementsWizardFactory
.createEstimoteRequirementsWizard() .fulfillRequirements(this, // onRequirementsFulfilled new Function0<Unit>() { @Override public Unit invoke() { Log.d("app", "requirements fulfilled"); proximityObserver.start(); 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; } });
POST Request StringRequest postRequest = new StringRequest(Request.Method.POST, url,
new Response.Listener<String>() { @Override public void onResponse(String response) { // response Log.d("Response", "(Succ)ess"); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { // error Log.d("Error.Response", "Error logging in"); } }
) {
@Override protected Map<String, String> getParams() { Map<String, String> params = new HashMap<String, String>(); params.put("username","ahmed"); params.put("password","afro"); params.put("beaconid", "0bad1f66ca2237d6f4afe723e2758a3d"); params.put("open","1");
return params; }
}; queue.add(postRequest);