Read and Write Permissions for android body storage

Source: Internet
Author: User

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 );

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.