Comments (7)
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.
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.
Note that this is all done inside an AsyncTask task
from kontakt-android-sdk.
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.
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.
Thanks @alishak - yes, the documentation was incorrect - that's corrected and flagged for update now. Thanks.
from kontakt-android-sdk.
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)
- VerifyError exception HOT 4
- Contribution HOT 2
- Diagnostic property code 0x06 HOT 3
- Delete the permission check HOT 3
- Improve logging API HOT 4
- ScanStatusListener.onScanError() improvements HOT 2
- Does't work on Android 12 HOT 2
- New dependency required when updating to version 7.0.2 HOT 8
- BeaconProScanning not working HOT 5
- does not recognize Beacons Pro equipment HOT 14
- Add Battery Level variable in Device class HOT 3
- ErrorCode in KontaktDeviceConnection.ConnectionListener's onErrorOccured HOT 2
- Can't Apply Configuration to a Beacon in Android 13 HOT 2
- regression- startScan failure on Android < 8 HOT 2
- typo in log: "D/SDK: : Stopping monitoring" HOT 3
- Candidate for NPE in InternalProximityManager HOT 1
- Is it possible to detect iOS and Android devices advertising as iBeacons? HOT 1
- IBeaconUniqueIdCachehas nothing to resolve
- Missing OkHttp method when initialising ProximityManager HOT 1
- the sdk crashed on Android 14 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kontakt-android-sdk.