Android Learning Series (3)-custom progress view and internal storage for automatic App update

Source: Internet
Author: User

The friendly visual perception and stable and error-free performance come from our pursuit of aesthetics and comprehensive consideration. I have always enjoyed it from a technical point of view.
This article is a must-have knowledge for android Developers. It is specially compiled and summarized for everyone. It is not perfect but useful.

This article is about 《Android Learning Series (2) -- download in the notification bar of App auto update", So it is only a point to the end.
1. Internal Storage
In consideration of the possibility that the user has disabled SDCard or the computer has been temporarily inserted into the computer and is in the disk connection status, we should ensure that our program can run normally under such circumstances. Therefore, we need to consider internal storage.
I have set the internal storage to the/data/xxxxxappxxxx/files directory. The core code is as follows:

Html # viewSource "commandName =" viewSource "highlighterId =" highlighter_213261 "> view sourceprint?
1 // Create directories and files
2 if(android.os.Environment.MEDIA_MOUNTED.equals(android.os.Environment.getExternalStorageState())){
3     updateDir = new File(Environment.getExternalStorageDirectory(),Global.downloadDir);
4 }else{
5     // Files directory
6     updateDir = getFilesDir();
7 }
8 updateFile = new File(updateDir.getPath(),getResources().getString(titleId)+".apk");

 2. Internal Storage Permissions
All of them run normally, but when we execute the running operation for the apk file, the prompt is as follows,
 
"Parsing package error "?? In fact, the file you downloaded may not necessarily be bad or wrong, or the permission of the android system may be improper. Add the following core code before execution:

View sourceprint?
1 String cmd = "chmod +x " +updateFile.getPath();
2 try {
3     Runtime.getRuntime().exec(cmd);
4 } catch (IOException e) {
5     e.printStackTrace();
6 }

3. A bug of the progress bar component is displayed in the notification bar.
Setting the visibility of the progress bar in the notification bar will crash for no reason.

View sourceprint?
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.