Hi I have made a simple app as per the getting started guide, however the onExitedRegion does not seem to trigger the notification. Any guidance would be appreciated.
I turned on the flip beacon off via the mobile app - so i could test…
package com.example.milesboyle.myapplication;
import android.app.Application;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import com.estimote.coresdk.observation.region.beacon.BeaconRegion;
import com.estimote.coresdk.recognition.packets.Beacon;
import com.estimote.coresdk.service.BeaconManager;
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.List;
import java.util.UUID;
/**
* Created by milesboyle on 22/08/2017.
*/
public class MyApplication extends Application {
private BeaconManager beaconManager;
// This is an AsyncTask - allows some 'work' to be done on a background
// thread i.e. off the UI thread. Android makes you do things this way or it
// will throw an exception
private class RESTApi extends AsyncTask {
@Override
protected Object doInBackground(Object[] params) {
System.out.println("doInBackground");
JSONObject payload = new JSONObject();
try {
// Here is the payload of the HTTP request to TRIRIGA
payload.put("spi:cstCheckInColourCO", "#00ff00");
} catch (JSONException e) {
e.printStackTrace();
}
HttpResponse<String> response = null;
try {
response = Unirest.put("https://xx")
// HTTP BASIC AUTH INFO
.basicAuth("xx", "xx")
// Additional HTTP headers
.header("Accept", "application/xhtml+xml")
.header("Content-Type", "application/xml")
.header("x-method-override", "PATCH")
.header("PATCHTYPE", "MERGE")
// Put the JSON payload as a String in the HTTP request
.body(payload.toString())
// Get the value back as a String
.asString();
} catch (UnirestException e) {
e.printStackTrace();
}
// Print out the HTTP response code to the Console
System.out.println(response.getCode());
// Print out the HTTP response headers to the Console
System.out.println(response.getHeaders());
return response.getBody();
}
protected void onPostExecute(String result) {
System.out.println("onPostExecute");
System.out.println(result);
}
}
@Override
public void onCreate() {
super.onCreate();
beaconManager = new BeaconManager(getApplicationContext());
// add this below:
beaconManager.setMonitoringListener(new BeaconManager.BeaconMonitoringListener() {
@Override
public void onEnteredRegion(BeaconRegion region, List<Beacon> beacons) {
System.out.println("ENTER REGION");
showNotification(
"NHS Welcome to your room",
"Your bed is S18"
+ " Floor 2, Room 6A "
+ " ");
new RESTApi().execute();
}
@Override
public void onExitedRegion(BeaconRegion region) {
// could add an "exit" notification too if you want (-:
System.out.println("EXIT REGION");
}
});
beaconManager.connect(new BeaconManager.ServiceReadyCallback() {
@Override
public void onServiceReady() {
beaconManager.startMonitoring(new BeaconRegion(
"anything",
UUID.fromString("9898FC3A-D619-4B07-8975-BE9A672F5270"),
3913, 39775));
}
});
}
public void showNotification(String title, String message) {
Intent notifyIntent = new Intent(this, MainActivity.class);
notifyIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivities(this, 0,
new Intent[] { notifyIntent }, PendingIntent.FLAG_UPDATE_CURRENT);
Notification notification = new Notification.Builder(this)
.setSmallIcon(android.R.drawable.ic_dialog_info)
.setContentTitle(title)
.setContentText(message)
.setAutoCancel(true)
.setContentIntent(pendingIntent)
.build();
notification.defaults |= Notification.DEFAULT_SOUND;
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(1, notification);
}
// private String getBasicAuth() {
// byte[] encodedBytes;
// encodedBytes = "username" + ":" + "password".getBytes();
//
// }
}