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); |
6 |
updateDir = getFilesDir(); |
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(); |
3 |
Runtime.getRuntime().exec(cmd); |
4 |
} catch (IOException e) { |
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?