Android Create folders and files and install other APK

Source: Internet
Author: User

First, create folders under Android

File sd=environment.getexternalstoragedirectory ();        String Path=sd.getpath () + "/notes";        File File=new file (path);        if (!file.exists ())           file.mkdir ();

II. create files under Android

HttpClient HttpClient = new Defaulthttpclient (); HttpGet httpget= New HttpGet ("http://img3.3lian.com/2006/016/09/031.jpg"); HttpResponse HttpResponse = Httpclient.execute (HttpGet), if (Httpresponse.getstatusline (). GetStatusCode () = = 200) { Total_length = Httpresponse.getentity (). Getcontentlength ();              is = Httpresponse.getentity (). getcontent ();              File File = new file (Environment.getexternalstoragedirectory (), "aupdata.jpg");              FOS = new FileOutputStream (file);              bis = new Bufferedinputstream (IS);           byte[] buffer = new byte[1024];         byte [] result_two = new byte [(int) total_length];             int len = 0;          int total=0;                        while (len = bis.read (buffer)) >-1) {system.arraycopy (buffer, 0, Result_two, Total, Len);        Fos.write (buffer, 0, Len);                   Total = Total + len; }        }
After the FileOutputStream defines the file, you can create the corresponding file by writing it with the. Write method.

Third, Android install other APK

                        Intent Intent = new Intent (); intent.setaction (Intent.action_view); File Install_file = new file (Environment.getexternalstoragedirectory (), "myweb.apk"); Intent.setdataandtype ( Uri.fromfile (Install_file), "application/vnd.android.package-archive"); StartActivity (intent);


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.