I've a process to send an image to server as per client/end-user wish(pick) from gallery and upload. But the task is to send an image file from an application, even-though user don't have an internet connection and it should send a file when he/she get it(internet connection again/back). I request you people to suggest some idea and it will helpful if I get snippet of code/sample. Thank you!
You can try the following:
Make an android service which gets started when application tries to send files but internet is not available.
Android service will wait for internet connectivity availability.
Store the http url and image uri for every upload request made during this time in SharedPreference.
When network becomes available fetch upload request from shared preference and make request one by one.
Hope this helps.
Related
I am new to web development. I had a web project with EJS templating. It redirects directly from the server. Using res.redirect() . I want to create a server for web and mobile both.
Question is... When i use res.json() it sends JSON data to client side. Can work for both.
It is possible to use res.redirect() for both. Web and mobile.
Pros and cons of res.rediret and res.json
Please explain. I appreciate your suggestions in adv. Thanks.
It is possible to use res.redirect() for both. Web and mobile.
If you mean can you use res.redirect() as an alternative to res.json() then the answer is NO. res.redirect() is not an alternative to res.json. res.redirect() only sends a code and a URL back to the client, there is no data in the response. You will still need to use res.json or res.send to get the data you need. Every time you use res.redirect() you are sending a response to the client telling them to make a brand new request to another location. You're not sending any real data. The android app will not get any content till you use res.json or res.send. Redirects just tell the client go get the data from somewhere else.
Below are example responses to an android app when the server uses res.json and res.redirect
res.redirect("/user")
//Response to Android app
302 /user
The response above means what you want is located at "/user" so the mobile app will need to make a request to
res.json(user)
//Response to Android app
{
name: "Arpit Yadav",
phone: 555-555
}
res.redirect sends status code 302 (if not specified), and location (route) to browser, after which browser redirects the request to the specified location, whereas res.json sets Content-Type: application/json and sends data to the browser.
Redirection is generally meant for browser only, but, you can use it for mobile. In that case, you have to handle the logic to re-request with updated location received from server that is not recommended.
In nutshell, both have different purpose. res.redirect to move clients to different route and res.json to actually sends the data.
I have 5,6 android app which uses same URL(hard coded in apps) to invoke HTTP requests, the problem is that if the URL is changed due some reasons i have to re upload all apps with new URL which is a problem for me and i am looking for a solution for this.
I can build a web service to check for valid URL at initialization or connect to a remote database to get new URL but problem is that they need static IP and in my case i don't have it.
Is there is any method to notify and send small amount of data without having static IP.
You can use a different way to include URL in your app, like a configuration file or some like this, and when you need to update the url you can do this with a simple GCM (Google Cloud Messaging) message with a payload, but you need to implement GCM requests handling in your app.
GCM permitt to send message without the need of a static IP
The best solution i found for this issue is to use MongoDB which free for <500mb i can easily update MongoDb and my app can retrive String from it.
I am working on an android application, in which we are required to upload an encrypted file to a server using VPN network on a mobile device. I have the method to encrypt the file, but I have no information how to upload a particular file to a remote server. Kindly suggest me some method to upload a particular file to the server. Also suggest me how to calculate the upload time.
Thanks!
Try this code $upload_time = time() - $_SERVER['REQUEST_TIME'];.The result will be in seconds
I creating an application that can teather the wifi and act as like a firewall to manage the sessions to their clients .
for example:
If i manage the clients http requests and response..after i authenticated the request ,then only the url has to be visible for them.otherwise it has to say page blocked.
In an Example provided by the google https://developers.google.com/analytics/devguides/collection/android/v2/sessions
It says it can manage sessions But I cant able to integrate it my project .Can anyone worked projects similar to this or anyone used analystics-api, help me to work on this
And how can i get the request page url from the user..
Try this example in your activity ..From this code you able manage your http requests and responses..session-handling-Exampe
Hope will help you..
In my android app i keep getting timeouts in the messages between the app and my server.
In an attempt to see if the problem is in the app or my server,
i want to try and Send an HTTP request from my app to
some other server i am sure is up and reliable and then see if i get timeouts.
Is there any server address i can check against?
Thanks in advance!
BTW : i am using a glass Fish servlet for my server
We've successfully sent a simple HTTP GET to google.com -- with a couple of fall-backs (I've also seen internic.org used) in the past, in similar cases.