Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

Download a file with Android, and showing the progress in a ProgressDialog

I am trying to write a simple application that gets updated. For this I need a simple function that can download a file and show the current progress in a ProgressDialog. I know how to do the ProgressDialog, but I'm not sure how to display the current progress and how to download the file in the first place.
by

2 Answers

akshay1995
Don't forget to add permissions to your manifest file if you're gonna be downloading stuff from the internet!

<manifest xmlns:android="<url>/apk/res/android"
package="com.example.helloandroid"
android:versionCode="1"
android:versionName="1.0">

<uses-sdk android:minSdkVersion="10" />

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
<uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>

<application
android:icon="@drawable/icon"
android:label="@string/app_name"
android:debuggable="true">

</application>

</manifest>
RoliMishra
Use Android Query library, very cool indeed.You can change it to use ProgressDialog as you see in other examples, this one will show progress view from your layout and hide it after completion.

File target = new File(new File(Environment.getExternalStorageDirectory(), "ApplicationName"), "tmp.pdf");
new AQuery(this).progress(R.id.progress_view).download(_competition.qualificationScoreCardsPdf(), target, new AjaxCallback<File>() {
public void callback(String url, File file, AjaxStatus status) {
if (file != null) {
// do something with file
}
}
});

Login / Signup to Answer the Question.