Difference between revisions of "Proximity App via SDK"

From ESE205 Wiki
Jump to: navigation, search
(Example Code for Each Part)
(Example Code for Each Part)
Line 60: Line 60:
  
 
==Example Code for Each Part==
 
==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);
 

Revision as of 23:01, 3 May 2018

Steps

  1. Prerequisites
    1. 1 x computer with android studio
    2. 1 x Android phone with android 5.0
    3. 1 x Estimote proximity beacon
  2. Proximity Beacon Setup
    1. Download estimote app
      1. Configure ->find beacons -> login -> enable Estimote monitoring
  3. Download Estimote Example App
    1. https://github.com/Estimote/Android-Proximity-SDK
    2. Import SDK into Android Studio
    3. Estimote will automatically import their basic Methods and app interface
  4. Add Permissions to build.Gradle
    1. In your build.gradle tab add estimote SDK lines that will grab your necessary permissions
      1. general-SDK
      2. perimeter-SDK
      3. Estimote-mustard
  5. Add Proximity Observer to Activity class
    1. Set up Cloud Credentials inside generated onCreate method
      1. Credentials will give your app the ability recognize specific beacon ID’s
    2. Add Proximity Observer Object
      1. To add the Proximity Object you will need to create a builder inside your onCreate method underneath your Credentials
  6. Define Proximity Zones
    1. Log onto Estimote app and select your beacon, in edit, select beacon attachments
      1. In beacon attachments define location and ownership of beacon
    2. Creating Proximity Zone Objects
      1. Add a Proximity Zone beneath your Proximity Observer Builder
        1. If desired, it is possible to create multiple zones for different beacons
  7. Start Proximity Observing
    1. Requires location permissions in your build.gradle
      1. ACCESS_FINE_LOCATION
    2. At the end of your onCreate Method define a new proximity zone “proximityObserver”
      1. Proximity observer will have 3 cases
        1. Requirements fulfilled - proximityObserver.start
        2. Requirements missing - log error message
        3. Requirements error - log error message
      2. Each case will return null.
  8. POST Requests
    1. You will need to create a post request so your app can talk to Amazon Web Services
    2. Need two instances of request
      1. 1st POST request will be under your proximity observer
        1. A generic POST template found online works perfectly
      2. Paste code in and modify parameters ensuring that they match up with the AWS side
        1. Username
        2. Password
        3. beaconID
        4. Open
          1. Set open to TRUE or 1
      3. 2nd POST request will be entered beneath onExit action
        1. 1st POST request will be under your proximity observer
          1. A generic POST template found online works perfectly
        2. Paste code in and modify parameters ensuring that they match up with the AWS side
          1. Username
          2. Password
          3. beaconID
          4. Open
            1. Set open to False or 0

You should be good to go!

Example Code for Each Part