I am building a mobile application that get all the information from a Java backend. The data is available through REST in JSON format. How would you manage to discover on the mobile device if the JSON is new or not? I was thinking of having one really simple JSON format file with only a timestamp that the mobile device checked each time to compare to what already stored...but it doesn't seems to be a good solution, at least I think. So are there other ways to do this? I am developing both the backend Java server application and the mobile device app (iOS).
Use HTTP Headers including the HTTP ETag. Here's an example in Java.
If-Modified-Since
Allows a 304 Not Modified to be returned if content is unchanged
If-None-Match
Allows a 304 Not Modified to be returned if content is unchanged
Related
The problem exactly like the following
I have one api which can provide some data and one apk,
I got my api response with my device and another different old response on the emulator with the same apk!
The emulator response is up to date with the latest changes while the other different response is before the changes.
The app uses retrofit without caching.
So what could be the problem?
Request contains only one header (access token)
Response contains headers like (ETag, Access-Control-Max-Age) but retrofit should not deal with them as there is no cache at all.
Screen shot from postman :
Also when waiting for a while all devices become up to date!
Are you sure with this?
The app uses retrofit without caching
Based on this https://github.com/square/retrofit/issues/678, I think that retrofit (OkHttp inside retrofit) caching your query.
You can change this behavior by 2 ways:
add ?_t=TIMESTAMP into your app query url
remove 'Access-Control-Max-Age' header from your server response
Or you can create new OkHttp client to retrofit and write something like that:
new OkHttpClient.Builder().cache(null).build();
or
Request.cacheControl(CacheControl.FORCE_NETWORK)
So what could be the problem?
If you dont' find the problem on the client, you should look for it on the server side. Any kind of caching (on the database, or on the HTTP response level) can show this behavior.
Without further knowledge about your setup and your test environment it is impossible to figure out what the problem could be. You write
Also when waiting for a while all devices become up to date
What does that mean? How do you determine, if your devices are up to date?
In your complicated case, with backend involved, you should provide an example project on Github where this behavior can be reproduced.
At the current moment, I am trying to understand how to add any data to GA. I read the data from my GA account using Core Reporting API and Managment API without any problems. But now I want to add the data (the number of phone calls) to GA account programmatically. Somebody can explain me step by step - how can I do this?
The Measurement Protocol is how we send data to Google Analytics. The JavaScript snippet that we use in our websites also uses the Measurement protocol as do the SDK's for Android and IOS. Unfortunately there is no (official) SDKs for the other languages like Java for instance.
That being said you can technically code it yourself in any language that can handle a HTTP get or a HTTP post. I have personally done it for C#.
POST /collect HTTP/1.1
Host: www.google-analytics.com
payload_data
The following parameters are required for each payload:
v=1 // Version.
&tid=UA-XXXXX-Y // Tracking ID / Property ID.
&cid=555 // Anonymous Client ID.
&t= // Hit Type.
A few tips to get you started.
Check out validating hits this is very useful in the beginning for debugging your requests.
some of the parameters are only valid for certain hit types. Make sure you check the documentation.
Cid is just a string it can be anything most people send a Guid its basically used by the server to identify a unique session.
if you are doing this for an application google analytics account remember to send screenview not pageview the same goes for web application.
check the realtime report on google analytics to see if your hits are getting recorded.
Update for question in comment:
I recommend while you are getting the idea of this you start with just using HTTP GET in a web browser. Its easer to test your requests against debug that way. For example put this in a browser.
https://google-analytics.com/debug/collect?v=1&tid=UA-123456-1&cid=5555&t=pageview&dp=%2FpageA
DP is document path and I am not sure why it is requiring that you send that.
ScreenView hit type VS PageView hit type.
There are two types of Google Analytics accounts ones for applications like android applications or sometimes web applications, and web sites. Application Google analytics accounts are meant to be used with ScreenView hit (the user checks a screen in the application) type and web accounts use PageViews (the user views a webpage). If you send a Pageview to an application Google Analytics account it will accept the hit but there will be no way for you to see the data. If you send a ScreenView to a web Google Analytics account it will again accept the data but you wont see it.
Sorry if this is a little general. Hopfully I can get pointed in the correct direction.
I have an android app that includes instant messaging. I want to add the functionality to send photos in messages as well. My backend is built on GAE and cloud endpoints and is written in Java.
So far, I've looked into google cloud storage, the blobstore, java servlet pages, etc. But a clear solution (or example using endpoints) has been impossible to find.
So, as the question states, how can I send and serve images from the blobstore using android and GAE endpoint backend?
Edit: This question is only regarding the back end. In android, I can do the http post easily enough. I'm just lost when it comes to doing this in endpoints
I suggest the following approach to implement what you require:
Pass the image data as base64 encoded text from your client.
On the server side, you can extract out the image content and then use one of many options that are available, which include Blobstore, Google Cloud Storage, etc. I suggest that you go with Google Cloud Storage because that is the recommended approach. If you prefer the Datastore, keep in mind that the data is limited to 1 MB in size, so you might hit that limit depending on the size of images that you are dealing with.
A SO question and answer here contains lot of relevant code that you could utilize: Sending images as a base64 string to a google cloud endpoint from cms
Why not using a simple HTTP POST to handler for image upload?
When I use the blobstore I typically have a pair of handlers one for uploading and one for serving images.
So, in your case I'll rather do a post to a URL sending the image file and some parameter than can link it to the proper place in the datastore (i.e. user ID).
Then, using endpoints I'll have the same linking key and display the image using the serving handler with the given parameter.
If you are already using endpoints you can follow #Romin 's suggestion and send the images as Base64 or upload your images in 2 steps using the blobstore/GCS service, first get the Upload URL (via endpoints) and then post your image to that URL.
So, I'm currently developing an app for a service which has a json-based (unfortunately) read only API. Retrieving content is no problem at all, however the only way to post content is using a form on their site which location is a PHP script. The service is open source so I know which fields the form expects, but whatever I send, it always results in a BAD REQUEST.
I captured the network traffic inside my browser and as far as I can see, the browser constructs a multipart form request, however when I copy the request and invoke it again using a REST client, a BAD REQUEST gets returned.
Is there a way to construct a http request in Android that simulates a form post?
If it's readonly I think you wouldn't be able to make requests with POST (it's assume for editing or adding things).
If you let me make you an advise, I recommend you using this project as a Library.
https://github.com/matessoftwaresolutions/AndroidHttpRestService
It makes you easy deal with apis, control network problems etc.
You can find a sample of use there.
You only have to:
Build your URL
Tell the component to execute in POST mode
Build your JSON
As I told you, I don't know even if it will work.
I hope it helps!!!
I have built a Java client for an external web service. When I send a request using Eclipse I get a response, but it is not the response I expect. I think I have traced this to one of the fields (a date field), but I can't work out if it is on my side that the conversion is wrong or on theirs, only that the response returns a different date than the one I sent.
How can I see the SOAP request in the xml format that it is sent in to check how the date field is being sent to the external service?
You just need to use a Jax-WS interceptor/handler. They are very easy to write. Netbeans actually has great built in support for them. But if you want to write one from scratch, check out this question
You can use Wireshark. It's pretty easy. If you don't know how to use it just type "wireshark soap" in Google.