Android project mobile security guard (the most complete code, the most detailed comments) 6 apk download

Source: Internet
Author: User

6. Download apk (implementation of the afinal framework and multi‑thread breakpoint download) afinal Introduction: idea. The apk file is in the bin directory of the Project. Change the file version in the configuration file, and then put the changed apk file into the project in the tomcat environment, in this way, the upgraded version file is obtained. Code:

FinalHttp finalHttp = new FinalHttp (); // create a FinalHttp object for multi-threaded breakpoint download File file = new File (Environment. getExternalStorageDirectory (), "temp.apk"); // you can specify finalHttp as the Directory and file name. download (updateInfo. getApkurl (), file. getAbsolutePath (), new AjaxCallBack <File> () {// download, rewrite 3 methods/*** if the download fails, print out Error */@ Override public void onFailure (Throwable t, int errorNo, String strMsg) {t. printStackTrace (); super. onFailure (t, errorNo, strMsg);}/*** method called during file download (Progress) * @ param count total file length * @ param current download progress */@ Override public void onLoading (long count, long current) {int progress = (int) (current * 100/count); TV _splash_progress.setText ("download progress:" + progress + "%"); super. onLoading (count, current);}/*** Method for successfully calling the File Download */@ Override public void onSuccess (File t) {Toast. makeText (getApplicationContext (), "Download successful, please replace and install", Toast. LENGTH_SHORT ). show (); super. onSuccess (t );}});

 

Add a TextView to the layout file to display the download progress. Set it to hide: code:
 <TextView  android:id="@+id/tv_splash_progress"  android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:textColor="#ff0000"  android:visibility="invisible"  android:layout_below="@+id/progressBar1"  android:layout_centerHorizontal="true"  android:layout_marginTop="16dp"/>  

 

Set it to visible before download, that is
tv_splash_progress.setVisibility(View.VISIBLE);  

 

Note: Set write sdcard permission: WRITE_EXTERNAL_STORAGE

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.