How to get starting and ending time of each download? - android

I am implementing one application related to downloads.
Based upon my requirement I want to get start and ending time each downloads.
For example the user downloads a app from android market after installing my app, then i need to get starting and ending time related to that download.
If any one know the solution please help me.
Thanks in advance.

Don't put direct link for download. Just put a php file which gets the address of file and let the user download it. In that case you can easily get the time with php. For the finish time it is not in your access but the best way is to use javascript on page which sends report of download to you via AJAX

Assuming that you want to display the start download time and the end download time the solution that comes to my mind is of using a AsyncTask where the start time can be displayed within the onPreExecute(), perform the download of app operation in doInBackground() and when the download finishes the time can be displayed in the onPostExecute(). HTH.

Related

Possible to integrate while loop into Android studio network connect?

I am facing a small issue with the android studio net work connect sample code.
Basically the code does exactly what i need, Press a button, it will fetch raw html a predetermined http.
However i was wondering if it is possible to make a while loop such that i do not need to press on the fetch button every time i want to get the data.
Regards.
http://developer.android.com/samples/NetworkConnect/index.html
What do you want exactly ? Do you want to refresh the web page or to check network connection ?
It seems you looking for refreshing the web page some period time.
While loop doesn't make sense. I suggest you to use Thread Handler or Timer.
Refer this link
you may get some ideas.

Html download with Async Task Android

I'm trying to make a web app using the WebView component. I need to modify the HTML before I show it to the user, so I tried to download it, modify it and the load it. I did this using the HTTP response and get classes and because of a series of exception I had to put them in an AsyncTask. Now the problem is that this solution works but it has a short delay because I have to wait for the Thread to end and then I can call the WebView.load() method either for the home and the other links. It is really ugly...do you have any solution to suggest me? Something without Async Tasks maybe?
The Android documentation states, that you should NEVER perform network operations on the main thread (otherwise, it will give you an exception).
Waiting for the AsyncTask to complete its background workflow is a natural process similar to think over the problem before giving the solution (your brain need to compute it in the background, if you will).
You will wait in any case. The server can't provide information instantly. But if you make request not in AsyncTask, it will block your application. And then android will offer to stop it. You dont need it. Instead of this you need to show something like process dialog.

Puling big data from Web Service in Android efficiently

I am having one web service in which i have list of countries, state and corresponding cities of it. Now I am little bit confused in pulling this data in my Android app. Right now I have only 2(USA,Canada) Country data with me but it might be increased in future. Also I have list of state in this country and yes the cities in every state.
I have one splash screen in my app in which I have written the logic of getting country and on the basis of that i am getting state and then cities for every state. But its long process and if i publish this a user will be frustrated by waiting time. So I don't want to use this way which takes longer time for pulling data. Is there any other way or suggestion for me to achieve this.
All suggestions are welcome.
you should use AsyncTask to perform any web data downloading (and uploading), it works in the background and does not block UI thread, so your user won't notice.
also, it might be a good idea to supply default country/city data along with your application and then download only changes/updates.
Use a Service or intent-service, to download the data in background. and when the download is complete you can display the downloaded data using onbind. service runs on a seperate thread.
You could simple use the system DownloadManager to get the files from your sources and later process them. The DownloadManager will even inform you when the file is fully downloaded.
Take a look a https://github.com/commonsguy/cw-android/blob/master/Internet/Download/src/com/commonsware/android/download/DownloadDemo.java for a simple example code using DownloadManager.

Android UI reliant on data from webservice - data doesn't come back in time

I have a screen in my application that is just a bunch of links. I am being directed to get the URLs from a web service so that they can be changed whenever and no android code would have to change. My problem is though I ask for data from AsyncTask and it does not come back before the user access the screen and then the links are either not there, or go back to a hardcoded resource I put in. Is there a better way to get data that affects the app like this?
why not just put in a progress dialog and then dismiss it in the onPostExecute? that way the link is always there and they cannot get ahead of the call
It might be a good idea to cache the links, so that the screen isn't blank, at least after the first time you run the app. You can update the list every time the user opens the page.

parse xml after some time android

In my app i need to parse the XML file & display info on activity. just like stock market as & when information at server got updated i need to parse the xml & display the info.I need to hit the server after 5 minutes & display the updated info on activity. I have tried using AsyncTask & timer but something going wrong.If any one is having demo then please provide link,tutorial..
It's extermely urgent..
thnx for any help....
Sounds like you want to run a polling loop in the background? You should be able to use a timer to kick off the check and an async task to actually request/parse. There's a bit of complexity in setting up the timer handling, the accepted answer to this question should help however:
How to get XML using AsyncTask and Timer?

Categories

Resources