Get JSON response from ProximityKit KitUrl android
Asked Answered
S

1

1

Overview of application: 1. Signup for Radius Developer's proximity kit and create Fences. 2. Get JSON response from PKKitURL in ProximityKit.properties file downloaded from website. 3. Parse JSON response to get lat and long. Get user's location and check for proximity.

Currently, i have done signing up, creating fences, downloading .properties file and all other basic things needed to integrate the ProximityKit's SDK.

Now I want to get the JSON response from the URL that's present in .properties file. I can retrieve the URL using the following code.

Configuration config = new Configuration(this);
Log.d(Const.DEBUG,
                "DeviceID = " + config.getDeviceId() + "\nKitUrl = "
                        + config.getKitUrl() + "\nLicenseKey = "
                        + config.getLicenseKey());

Sample JSON response:

{"kit":{"id":2837,"name":"My Kit","created_at":"2014-06-20T10:42:46.999Z","updated_at":"2014-06-20T10:42:46.999Z","links":{"map":"/api/maps/823"},"map":{"id":823,"name":"Wasp Hyderabad","created_at":"2014-06-20T16:20:13.504Z","updated_at":"2014-06-24T12:08:47.470Z","location":["17.4367","78.505243"],"overlays":[{"type":"circle","id":1968,"name":"Wasp Hyd Office","identifier":"pk-circleoverlay-1968","center":[17.443815,78.502657],"radius":197.846424},{"type":"circle","id":1969,"name":"Secunderabad","identifier":"pk-circleoverlay-1969","center":[17.437274,78.504884],"radius":257.538757}]},"ibeacons":[]}}

If i directly try to access the url and get the response, i get a AuthFailureError, which i guess is because of some authentication issue. My issue is how do i get this JSON response to my application?

I have all the required parameters in the .properties file, but i am not sure, how to send them to the server, to authenticate. Can anyone, who has been using RadiusNetwork's ProximityKit, help me out.

Shulamith answered 1/7, 2014 at 13:1 Comment(1)
Is there a reason you are trying to get the raw JSON instead of using the callback iBeaconDataUpdate?Eyecup
E
0

Making a web URL request is not the supported way to work with ProximityKit. Use the iBeaconDataUpdate callback and read from the provided IBeaconData to get the various metadata.

For example, to get say the welcomeMessage metadata:

public void iBeaconDataUpdate(IBeacon iBeacon, 
                              IBeaconData data, 
                              DataProviderException e) {
    if (iBeacon != null && data != null) {
        String displayString = iBeacon.getProximityUuid() + " " +
                iBeacon.getMajor() + " " + iBeacon.getMinor() + "\n" +
                "Welcome message:" + data.get("welcomeMessage");
        Log.d(TAG, "iBeacon Data: " + displayString);
    }
}

Also, be aware that ProximityKit will automatically register all of these regions for you. So you won't need to then tell the application it needs to start monitoring for them.

For more information on the ProximityKit API have a look at their Javadocs: http://developer.radiusnetworks.com/ibeacon/android/pro/javadocs/com/radiusnetworks/proximity/ProximityKitNotifier.html

Eyecup answered 1/7, 2014 at 18:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.