I have an Android app that is currently in the Google Play store. On my server, I generate Zip files containing JSON information. The server takes parameters from the Android app and generates an appropriate Zip file which the Android app downloads, unzips and processes.
I currently user he AndroidHttpClient method, but I suspect the HTTPUrlConnection would have been a better choice.
What would the approach be for using HTTPUrlConnection?
Will it handle situations where the Android app may make a call on a public Wifi which could cause a redirect? Is there any sample code that I could reference for doing this?
Thanks
JOhn
terramia.net/painter/HTTPClient/doc/urlcon_vs_httpclient.html to the pros and cons of httpclient and httpurlconection.
yes HTTPUrlConnection can be a better chocice.
why are you ziping at server and than downloading and than processing, please write some apis that sorer can respond on yours request and can send json data straight. it will save time complexity and space-complexity to some extent. just treat as my suggestion.
Related
I'm new to android, I'm trying to build an android app that is a front for a web portal. For example, Airbnb. They have a website, but they also have an android app that, using it's own layout, will show listings from their website.
There are many websites that teach how to or even directly convert your website to android apps. However, this will result in an app that loads too slowly and is unresponsive due to CPU usage.
Could anyone share any tutorial/guide to learn how to do this myself?
Million thanks.
To actually load data from a web server you're gonna need and API which usually delivers the proper date using JSON or XML format so that you can properly parse and display that data. Building this API is in it self a complete course on its own.
But connecting to and requesting data from the API is usually done using some networking libraries. These are some of the better know libraries for this purpose.
OkHttp: A complete library with a set of tools for handling network connections and HTTP requests.
RetroFit:Type-safe HTTP client for Android and Java by Square, Inc. which is built on top of OkHttp.
Async-Http-Client:
The Async Http Client library's purpose is to allow Java applications
to easily execute HTTP requests and asynchronously process the HTTP
responses. The library also supports the WebSocket Protocol. The Async
HTTP Client library is simple to use.
There tons of other good libraries.
its called webservices
Through android you get data in form of json from a web server and then return in custom view as you want.
Follow this link hope it will help
Step by Step Method to Access Webservice from Android
you would have to write an API/Web service or use if already exits to fetch data from web server. Basically the concept is that, the website itself must be pulling data from some database, so write an API which would fetch the data from same API and return JSON data and consume the API from your android app.
If you know PHP refere to this for the help :http://www.codeproject.com/Articles/267023/Send-and-receive-json-between-android-and-php
You can write WebService, in programming it generally refers to a web page(ex. Airbnb), that can be called from your android application which can pass in data to it, or receive data from it.
WebService is basically like a 'method' or 'function' in a normal programming language; except you're calling it over the internet.
The first thing is you have to create a Web Service. The Web Service will be your "bridge" to consume the data from other Website like airbnb or others and return the data to your android through json format for example.
You can create a Web Service using many languages like C#, Java, PHP, etc. I would like to recommend you to use the language that you know the most.
You can try to google this
Cheers
I'm developing my first android application, I'm trying to send video files I've recorded and saved in the applications External Cache Directory as well as other data like usernames, etc. I have a play application running on my server and have a mySQL DB running on my server.
I have experience with JDBC and oracle, but am unsure of how I should make the connection between the android app and the play app, I'm thinking I don't want the android app talking to the mySQL DB ever! that I'll send a JSON object from my android application to my play application, the play application will then take the JSON object parse it and update the DB with the user details and a pointer to the video file and also add the video file to the designated folder.
I'm unsure how to implement the connection on the the android app, do I create a new activity or maybe a fragment for the connection to the play app? a link to a simple tutorial taking a video file and sending it as a JSON object to a play application would really get me going.
I realize that might be a bit much to ask.
I was reading this post MultiPartEntity and thought it might be along the lines of how I would make the connection from the android app to the play app, but was unsure if it was using JSON(the comments suggest it does, but I can't see any JSON object creation)
is MultiPartEntity a good solution for my connection needs?
How do I deal with the JSON object when I receive it on the server end?
I'm thinking I'll have a route set up to deal with, but again a link to a similar example would be great.
Any help pointing me in the right direction is appreciated.
Your Play! application must have an endpoint to send data with post method (RestFul Web Service), Play! is Restful, just handle the uploaded file in your Action. In your Android Application, you can send data with Volley Library follow this link to do that How to multipart data using Android Volley
or your follow this tutorial with php web service but with what you want http://www.androidhive.info/2014/12/android-uploading-camera-image-video-to-server-with-progress-bar/
I have an asp web page which needs to grab an xls file from the device storage area on my android tablet, convert it into bytes and store it in my SQL database.
I can do the converting and storing bit but I have no idea as to how to get the file using VB.
Can anyone tell me how I can get the file without the user having to search for it using an upload control?
I would also like to delete the file after processing..
Thank you..
Derek.
In order to think about this we need to have clear in our minds where the division between client and server exists: You've got a webserver running ASP and a client running a webbrowser on the android platform.
The file you are trying to upload exists on the client. As such any code which does the uploading will have to run on the client and, as the client is running on android, it's unlikely it'll be VB doing the uploading. You're likely to need to use a scripting language like Javascript and, if you care about cross-browser support, be careful how you do it.
The server cannot get the file directly from the client due to common security restrictions.
Once the client side script has got the file, it'd usually send the data to the server using a webservice or other endpoint, deletion of the file can then happen after that.
I have some questions about developing a Android application which shall be able to communicate with a NodeJS server.
The Android application gathers some data and saves everything in a .csv file.
This file now needs to be uploaded to a NodeJS server. The NodeJS server should save the file as well as storing the content in a MongoDB.
My question now is how I should implement the communication between the Android device and the server.
I know how to upload a single file to a NodeJS server using a HttpURLConnection with a DataOutputStream.
But I need more than just uploading the file because I need a unique identification of each Android device.
I thought about using the (encrypted) Google account E-Mail address of the user to distinguish the devices. I am not interested in knowing who uploads which data but I need to store the data for each device separately.
The problem is that I don't know how to communicate between the device and the server.
If I upload a file via HttpURLConnection and DataOutptStream it seems that I can only upload the file without any additional information like the unique key for the device.
I also thought about uploading the file via sockets. But I am not sure how to handle huge file sizes (5 MB or more).
I am not looking for code fragments. I rather need some hints to the right direction. Hopefully my problem was stated clearly and someone can help me with this.
Using a HttpUrlConnection on the Android side, and a RESTful server on the Node side would be a straightforward option.
You can embed information into the URL in a RESTful way:
pathParam: www.address.com/api/save/{clientId}/data
queryParam: www.address.com/api/save/data?c={clientID}
each uniquely identifying the client. This can be whatever scheme you choose. You will have to build the HttpUrlConnection each time as the URI is unique, and important!
The server side can then route the URL however you see fit. Node has a number of packages to aid in that (Express, Restify, etc.). Basically you'll grab the body of the request to store into your DB, but the other parameters are available too so it's all a unique and separated transaction.
Edit: The package you use for RESTful handling can stream large files for you as well. Processing of the request can really begin once the data is fully uploaded to the server.
Using a socket would be nearly just as easy. The most difficult part will be 'making your own protocol' which in reality could be very simple.
Upload 1 file at at time by sending data to the socket like this:
54::{filename:'myfilename.txt',length:13023,hash:'ss23vd'}xxxxxxxxxxx...
54= length of the JSON txt
:: = the delimiter between the length and the JSON
{JSON} = additional data you need
xxx... = 13023 bytes of data
Then once all the data is sent you can disconnect... OR if you need to send another file, you know where the next set of data should be.
And since node.js is javascript you already have wonderful JSON support to parse the JSON for you.
Would I suggest using a socket? Probably not. Because if you ever have to upload additional files at the same time, HTTP and node.js HTTP modules might do a better job. But if you can guarantee nothing will ever change, then sure, why not... But that's a bad attitude to have towards development.
Hi and thanks for any suggestion,
I have done my homework and tried to find an answer on SO and around, but so far I have been unable to find a solution.
I am trying to build some kind of FileManager to allow user to upload files on websites (any website, for example add an attachment to a mail in yahoo mail...)
Therefore my application registers a filter so that when the browser requests a file to upload the app opens up and provide the file to the requester (the web browser).
My question is:
is there a way for me to retrieve the url of the website to which the file is uploaded ?
I'm not sure I understood your question currently. my answer is relevant with the assumption: you want to have a direct download url to the file that been uploaded, and you wish to use this url in some point in the future to download that file...
I am afraid there is really no way getting such information.
there are many obstacles in the way of getting url to the file that been uploaded:
there is no any system broadcast / event that been sent in this scansion
even if the upload process was managed and initiated from you own application with you own WebView - the website you uploading to not necessarily provide you information of what is the url of the uploaded file. I know for sure that companies like yahoo not provide you this url.
if that's not enough - there is no necessarily such url at all!
the fact is that the server you uploading to is not necasserly doing anything with the uploaded file, or just not exposing him to public access with url.
from the reasons I mentioned, developing app as you which can be done only with servers providing their own API for upload files, and returns you the url as respond.
of-course each server has it own API (if at all) and you should speak with each one of the servers you'd like to support with it own language. sort of mission impossible if you want to support most of the big sites...
I had similar problem as to how can I get the URL where my file is uploaded. The answer is simple and lies in your Android code.
For uploading a file to some place, you need to know URL of the server/website.
So lets say you are uploading a file to
www.yoursite.com/appdatafolder/
For uploading to the file to the given address, you have to have a php script file sitting there, which will communicate with your android code for uploading the data.
Lets consider the address is:
www.yoursite.com/appdatafolder/upload.php
Now it depends on your code on how did you wrote your php script, in my case, I also send the name of the file to upload.php file, you can ignore it if you want or your script follows some other algo.
Lets say you want to upload importantfile.txt, so the url for uploading the file becomes
www.yoursite.com/appdatafolder/upload.php?filename="importantfile.txt"
The address you need to provide to the user in order to download the file becomes:
www.yoursite.com/appdatafolder/importantfile.txt
Now what you can do is save this address in a local database on your phone and use it whenever the user wants to download the file.
If you are afraid of securing the files which can be accessed/downloaded
www.yoursite.com/appdatafolder/
you can use htaccess. There are alot of other security mechanisms out there for securing data on the server from hacking. htaccess is simplest example.
So this is the easiest and hassel free way of solving your problem.
If you want, I can provide the php script I used.
Hope this helps.
If their is no secure layer on the web site, data sniffing by the app could be a kind of solution. you'll also probably need to deal with content encoding like gzip.
You'll need to filter the result's. It is easy to do: You just need to look at the application level in the OSI model.
Then you can apply a second filter if you know the ip address or the hostname of the concerned site.
There is even one more filter if you know the request method. But most it is get or post most of the time.
Have you looked at this question: Android file chooser? It has great example code as well as a link to a GitHub project (aFileChooser).