Get JSON response from ProximityKit KitUrl android

本小妞迷上赌 提交于 2020-01-06 04:03:07

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/24510987/get-json-response-from-proximitykit-kiturl-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!