Git Product home page Git Product logo

Comments (7)

stoprocent avatar stoprocent commented on July 27, 2024

Hi, I'm not Android developer but as far I see this is more REST API related question.
Are you sending this request using POST HTTP Method?
Request parameters should be send as form urlencoded body.

from kontakt-android-sdk.

alishak avatar alishak commented on July 27, 2024

Here is a code snippet used to send a POST request through HTTPS. The response String returns an "update successful." message.

Example for a name value pair:

NameValuePair accept = new BasicNameValuePair("Accept", "application/vnd.com.kontakt+json;version=5");


String url = "https://api.kontakt.io/device/update?&deviceType=beacon&tx_power=4&uniqueId=tk4t";

HttpPost post = new HttpPost(url);
post.addHeader(api_key.getName(), api_key.getValue());
post.addHeader(accept.getName(), accept.getValue());

try {
    post.setEntity(new UrlEncodedFormEntity(requests, HTTP.UTF_8));
} catch(UnsupportedEncodingException e) {
    Log.e("ENTITY", e.getMessage());
}

HttpClient client = new DefaultHttpClient();

HttpResponse httpResponse;

try {
    httpResponse = client.execute(post);
    int responseCode = httpResponse.getStatusLine().getStatusCode();
    String message = httpResponse.getStatusLine().getReasonPhrase();

    HttpEntity entity = httpResponse.getEntity();

    if (entity != null) {

        InputStream instream = entity.getContent();
        String response = convertStreamToString(instream);

        // Closing the input stream will trigger connection release
        instream.close();
    }

} catch (ClientProtocolException e)  {
    client.getConnectionManager().shutdown();
    e.printStackTrace();
} catch (IOException e) {
    client.getConnectionManager().shutdown();
    e.printStackTrace();
}

from kontakt-android-sdk.

alishak avatar alishak commented on July 27, 2024

Note that this is all done inside an AsyncTask task

from kontakt-android-sdk.

dawidgdanski avatar dawidgdanski commented on July 27, 2024

Hey @alishak, try sending your POST request with the url https://api.kontakt.io/device/update and move all the parameters to the UrlEncodedFormEntity (http://developer.android.com/reference/org/apache/http/client/entity/UrlEncodedFormEntity.html).

You specified incorrect parameter name to be updated. Instead of tx_power there should be txPower. I was wrong saying about case sensitivity in device type. The deviceType can be of type BEACON or beacon.

To avoid the mistakes like yours, you can use KontaktApiClient which allows to perform CRU operations on /device resource.

Let us know once you succeed please and close the issue if everything is correct. Thanks.

from kontakt-android-sdk.

alishak avatar alishak commented on July 27, 2024

Hello!

In case anyone else runs into this issue, the problem was the txPower parameter name. I would just like to point out that there may be a typo in the documentation: http://docs.kontakt.io/rest-api/resources/#update-device

Both UrlEncodedFormEntity AND NameValuePair will work for headers.

Thank you.

from kontakt-android-sdk.

simontoulson avatar simontoulson commented on July 27, 2024

Thanks @alishak - yes, the documentation was incorrect - that's corrected and flagged for update now. Thanks.

from kontakt-android-sdk.

mittalprayag25 avatar mittalprayag25 commented on July 27, 2024

Hi Everyone,

I am working on Beacon application. I have created a service that runs at
background and started it with START_STICKY. The problem I am facing is in
registerMonitoringListener . My onRegionAbandoned and onRegionEntered
methods are getting called again and again when I am range of beacons. My
worry is when I am in range onRegionEntered should be called once and
thats it and onRegionAbandoned top be called when I move out of it. But
when I am in range both the functions are getting called again and again.
Is this the normal behaviour or else I am doing anything wrong.

Regards

Prayag

On Mon, May 25, 2015 at 1:06 PM, simontoulson [email protected]
wrote:

Thanks @alishak https://github.com/alishak - yes, the documentation was
incorrect - that's corrected and flagged for update now. Thanks.


Reply to this email directly or view it on GitHub
https://github.com/kontaktio/Android-SDK/issues/4#issuecomment-105154226
.

from kontakt-android-sdk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.