To implement an automatic update function, I need to download an APK package and then call the system installation to install this APK, that is, download myself and install myself.
I downloaded the APK to the SD card and everything went well.
However, if I download the APK to the body storage space, it will be a problem.
1. Download to the/data/xx. xx. xx/Files directory. the download is successful, but a parsing package error is prompted during installation.
2. Download to/system or/cache. The file is not created successfully, and it seems to be a permission issue.
Could you tell me how I can complete the automatic update function in the body storage, because I cannot force others to insert an SD for use.
I callCode:
String tpath = downloadfilepath;
File mainfile = new file (tpath );
If (mainfile. exists ()){
Uri DATA = URI. fromfile (mainfile );
Intent intent = new intent (intent. action_view );
Intent. setdataandtype (data,
"Application/vnd. Android. Package-Archive ");
Startactivity (intent );
}
Stored after the downloaded file:
File tfile = new file (SaveFilePath); // The SaveFilePath can be an SD card or a body storage.
If (tfile. exists ())
{
Tfile. Delete ();
}
If (! Tfile. exists ())
{
Fileoutputstream Fos = new fileoutputstream (tfile );
FOS. Write (savebuffer );
FOS. Flush ();
FOS. Close ();
If (tfile. exists ())
{
Return tfile;
}
}
Thank you for your answers.
Solved many issues
Only File Permission can be modified.
String command = "chmod 777" + tfile. getabsolutepath ();
Runtime runtime = runtime. getruntime ();
Runtime.exe C (command );