Android java download files after installing






















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.

There are many ways to download files. Following I will post most common ways; it is up to you to decide which method is better for your app.

This method will allow you to execute some background processes and update the UI at the same time in this case, we'll update a progress bar. The method above doInBackground runs always on a background thread.

You shouldn't do any UI tasks there. On the other hand, the onProgressUpdate and onPreExecute run on the UI thread, so there you can change the progress bar:. The big question here is: how do I update my activity from a service? In the next example we are going to use two classes you may not be aware of: ResultReceiver and IntentService.

ResultReceiver is the one that will allow us to update our thread from a service; IntentService is a subclass of Service which spawns a thread to do background work from there you should know that a Service runs actually in the same thread of your app; when you extends Service , you must manually spawn new threads to run CPU blocking operations.

Groundy is a library that basically helps you run pieces of code in a background service, and it is based on the ResultReceiver concept shown above. This library is deprecated at the moment. This is how the whole code would look like:.

A GroundyTask implementation used by Groundy to download the file and show the progress:. It couldn't be easier I think. Just grab the latest jar from Github and you are ready to go. Keep in mind that Groundy 's main purpose is to make calls to external REST apis in a background service and post results to the UI with easily. If you are doing something like that in your app, it could be really useful.

GingerBread brought a new feature, DownloadManager , which allows you to download files easily and delegate the hard work of handling threads, streams, etc. Method's name explains it all. Once you are sure DownloadManager is available, you can do something like this:. First and second methods are just the tip of the iceberg.

There are lots of things you have to keep in mind if you want your app to be robust. Here is a brief list:. Unless you need detailed control of the download process, then consider using DownloadManager 3 because it already handles most of the items listed above.

But also consider that your needs may change. For example, DownloadManager does no response caching. It will blindly download the same big file multiple times. There's no easy way to fix it after the fact. So the initial effort of learning the basic, standard tools can be a good investment. This class was deprecated in API level ProgressDialog is a modal dialog, which prevents the user from interacting with the app.

Instead of using this class, you should use a progress indicator like ProgressBar, which can be embedded in your app's UI. Alternatively, you can use a notification to inform the user of the task's progress. For more details Link.

Don't forget to add permissions to your manifest file if you're gonna be downloading stuff from the internet! Yes the code above will work. But if you are updating your progressbar in onProgressUpdate of Asynctask and you press back button or finish your activity AsyncTask looses its track with your UI.

And when you go back to your activity, even if download is running in background you will see no update on progressbar. So on OnResume try to run a thread like runOnUIThread with a timer task that updates ur progressbar with values updating from the AsyncTask running background. I'd recommend you to use my Project Netroid , It's based on Volley. I have added some features to it such as multi-events callback, file download management.

This could be of some help. Improve this answer. Jon 7, 6 6 gold badges 49 49 silver badges 67 67 bronze badges. Is there any way that the prompt to the user could be avoided? I'm attempting to update an app in an automated fashion as part of a test suite, and need to avoid reliance on a user to accept the download.

TomBennett No, the prompt cannot be avoided, for security reasons. Packages can only be installed if your app is signed with the same signature as the ROM - stackoverflow. Downloading worked for me, but starting the intent to install did not. I used this answer and then the following to trigger the install stackoverflow. Downloading was working but I was getting an error that there was no activity found to handle intent.

Show 15 more comments. Jared Rummler But when I pull from emulator that. Can you tell me what is the problem? Child did you download the apk to a publicly accessible folder? I downloaded it to my application's files dir at first, but that was giving me the parse error. I now download it to Environment. Please for the love of god use getExternalCacheDir.

Saving to the Downloads folder just leaves junk on the device when the user uninstalls the application. Trust me, no one who intentionally downloads an apk on the web will want to keep the apk in the downloads folder.

Than you for your answer. Really helped me. But i faced with java. The problem was in this line: urlConnection. Sorry for the long delay answering. I think that last updates may deprecated some functions for security reasons. Unfortunately, I'm using ionic to develop mobile apps, so, I don't know why the script above doesn't work anymore. Show 8 more comments. Email Id : muhammad. SelfInstall01; import java. Copy both APK files to the root directory of your Android device.

Run the APK files to install them onto your device. Make sure that the JAR file doesn't have any spaces in the filename. Run the file by using phoneMe and selecting the file on your device. Install and use JBED. Download the JBED archive file and unzip it on your computer.

Run the APK file to install it on your device. You can push the libjbedvm. Copy any JAR files you want to run to their own directory on your phone. Install and use JBlend. Download the JBlend archive file and extract the contents. Copy the files onto your phone's storage. Install the Root Explorer application. Copy the following files to the destination specified: ibDxDrmJava. Use JBlend to select the files to load them. Install Netmite. Download the latest release from the Netmite website.

Copy the APK file to your phone and then run it to install Netmite. Copy the converted APK file onto your phone and run it to install. Repeat this for all the JAR files that you want to run. Open Netmite on your phone and use it to select any of your installed JAR files. Method 2.

Install the Chrome Remote Desktop app on your Android device. On OS X, double-click the. Close any browser windows before starting the installation, as they will need to be restarted anyway after installation is complete.

Follow the installation steps. Read each screen of the installation program. Java will try to install extra software such as browser toolbars unless you uncheck the boxes. If you don't want your browser changed, make sure to read each screen carefully. Test the installation. After you have finished installing Java, test the installation to make sure everything went OK. You can find the Java testing applet on the Java website, or by searching for "java test" and selecting the first result.

You will need to allow the plugin to run, and you may be asked multiple times before it can load. This is because, in general, Java can be a dangerous tool which can grant others access to your computer if you are not careful. Always be sure you trust the website that you are running Java applets on.

It could mean you have to clear up space. Try to delete unwanted files. Yes No. Not Helpful 4 Helpful 8.

You only need to download the JDK if you are looking to develop or debug Java-based software. If you're just looking to run Java applications, the JRE is enough. You get the JRE by normally installing Java. Not Helpful 7 Helpful 7. If it's in the installer, redownload the installer. If the installer works, download jarfix.



0コメント

  • 1000 / 1000