Android first boot through the Setup Wizard to copy files to the SDcard directory

Source: Internet
Author: User

MTK platform Machine, the first opportunity to start the OOBE Setup Wizard, we can add an interface to the application to copy files from the/system/directory to the/mnt/sdcard/directory.

1. First compile to copy the file from the code path to the corresponding out directory, can be used in the Mk file to implement:
Method ①: If the file is small, you can use the copy-by-article method as follows:

Cur_path: = vendor/thirdparty/app/tchipproduct_copy_files + =  $ (cur_path)/bootanimation.zip:system/media/ Bootanimation.zip  

Method ②: If the file structure is more complex, you can use the following script:

Cur_path: = vendor/thirdparty/app/qifeitchip_files: = $ (Shell ls $ (cur_path)/multimedia) Product_copy_files + = $ ( foreach file, $ (tchip_files),         $ (cur_path)/multimedia/$ (file): system/media/multimedia/$ (file))

2. Modify Boot Wizard OOBE
mediatek/packages/apps/oobe/
① adds permissions to the Androidmanifest.xml and declares our custom activity:

<uses-permission android:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android: Name= "Android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/> <activity            android:name= ". Basic. CopyFiles "></activity>

② Write acitivity content:

Package com.mediatek.oobe.basic; Import Android.app.activity;import android.content.intent;import Android.net.uri;import Android.os.Bundle;import Android.os.environment;import Android.os.handler;import Android.os.message;import Android.util.Log;import Android.widget.progressbar;import Android.widget.Toast; Import Java.io.file;import Java.io.fileinputstream;import Java.io.filenotfoundexception;import Java.io.fileoutputstream;import Java.io.ioexception;import Java.io.inputstream;import Java.io.OutputStream;import COM.MEDIATEK.OOBE.R; /** * Created by Alex on 2015/1/12.     */public class CopyFiles extends Activity {ProgressBar ProgressBar;        @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);        Setcontentview (R.layout.copyfiles);        ProgressBar = (ProgressBar) Findviewbyid (R.id.progressbar);        Copy ();        New Thread (New Timethread ()). Start ();    Copy (); } final Handler Timehandler = new Handler () {        public void Handlemessage (Message msg) {switch (msg.what) {Case 1:/                    /Toast.maketext (copyfiles.this, "Copy succeeded", Toast.length_short). Show ();            Finish ();        } super.handlemessage (msg);     }    };                public class Timethread implements Runnable {@Override public void run () {try {                Copy ();                Message message = new Message ();                Message.what = 1;            Timehandler.sendmessage (message);            } catch (Exception e) {e.printstacktrace ();        }}} private void Copy () {final String Frompath = "/system/media/multimedia";        Final String Frompath = "/mnt/sdcard/test";        Final String topath_music = "/mnt/sdcard/music";        Final String Topath_movie = "/mnt/sdcard/movie";        string[] filename = null;        File File = new file (Frompath); if (File.exists ()) {filename = File.list ();        } File Filestoremusic = new file (topath_music);        if (!filestoremusic.exists ()) {Filestoremusic.mkdir ();        } File Filestoremovie = new file (Topath_movie);        if (!filestoremovie.exists ()) {Filestoremovie.mkdir ();            } for (int i = 0; i < filename.length; i++) {log.d ("CopyFiles", Filename[i]);            InputStream fosfrom = null;            OutputStream Fosto;                try {fosfrom = new FileInputStream (Frompath + "/" + filename[i]);                if (i==3) {fosto = new FileOutputStream (Topath_movie + "/" + filename[i]);                } else {fosto = new FileOutputStream (Topath_music + "/" + filename[i]);                } byte bt[] = new byte[1024];                int C;                while ((c = Fosfrom.read (BT)) > 0) {fosto.write (BT, 0, C);       }      } catch (FileNotFoundException e) {e.printstacktrace ();            } catch (IOException e) {e.printstacktrace ();            } try {fosfrom.close ();            } catch (IOException e) {e.printstacktrace ();        } progressbar.setprogress (i + 1);                if (i== filename.length-1) {Message message = new Message ();                Message.what = 1;        Timehandler.sendmessage (message); }} try {Sendbroadcast (new Intent (intent.action_media_mounted, Uri.parse ("file://" + Environment        . getExternalStorageDirectory ())));        } catch (Exception e) {e.printstacktrace (); }    }}

③ Layout file:

<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "    android:layout_width=" match_parent "    android:layout_height=" match_parent ">     < LinearLayout        android:layout_width= "fill_parent"        android:orientation= "vertical"        android:gravity= " Center "        android:layout_height=" fill_parent ">         <progressbar            style="? android:attr/ Progressbarstylehorizontal "            android:layout_width=" fill_parent "            android:layout_height=" Wrap_content "            android:id= "@+id/progressbar"            android:max= "6"            android:layout_gravity= "center_vertical"/>         <textview            android:id= "@+id/copytext"            android:layout_width= "fill_parent"            android:layout _height= "Wrap_content"            android:text= "@string/file_copying"/>      </linearlayout></ Linearlayout>







Android first boot through the Setup Wizard to copy files to the SDcard directory

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.