Android requires installation and rewriting to migrate to the SD card app2sd

Source: Internet
Author: User

/*************************************** *******************

Everyone knows that blog writing will be very tiring and hopefully

Reprinted please indicate the source: http://blog.csdn.net/ta893115871

Please do not pity your mouse, (* ^__ ^ *) Xi ......

**************************************** *********************/

Before sdk2.2 is released, Android installation applications can only be installed in the mobile phone memory, and up to 50 ~ 100 sets of programs, if the "angry brid" Angry Birds installed on the mobile phone. Yes.

Notified.

When an SD card is found during installation, it is automatically installed on the SD card. If not, click the button to go to the application settings, some users decide whether to move the application to the SD card or to move the program back to the mobile phone from the SD card.

. Java File

Package COM. example. app2sd; import android. OS. bundle; import android. app. activity; import android. content. intent; import android. view. view; import android. view. view. onclicklistener; import android. widget. button; public class app2sdactivity extends activity {private button mbutton; @ override public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); mbutton = (button) This. findviewbyid (R. id. button_id); mbutton. setonclicklistener (New onclicklistener () {public void onclick (view v) {// todo auto-generated method stub // go to application settings through the button event, the user determines whether to move the application to the SD card startactivity (new intent ("android. intent. action. manage_package_storage "));}});}}

Androidmanifest. xml

The key of this program is Android: installlocation = "preferexternal" in androidmainfest. xml. Set to preferexternal so that the program is installed on the SD card by default. Another important point is that the API level of the program must be set to Android: minsdkversion to "8" or later.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="com.example.app2sd"    android:versionCode="1"    android:versionName="1.0"    android:installLocation="preferExternal"     ><!-- move app to sd card you  should in mainfest to add   android:installLocation="preferExternal"   and   sdk should >=8  that version is 2.2  . this function added in after 2.2 version.  -->    <uses-sdk        android:minSdkVersion="8"        android:targetSdkVersion="15" />    <application        android:icon="@drawable/ic_launcher"        android:label="@string/app_name"        android:theme="@style/AppTheme" >        <activity            android:name=".App2SDActivity"            android:label="@string/title_activity_app2_sd" >            <intent-filter>                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />            </intent-filter>        </activity>    </application></manifest>

 

If you develop Android: minsdkversion with the old SDK version earlier than 8, add the Android: installlocation = "preferexternal" attribute to androidmainfest. xml directly. What will happen?

The Android: installlocation = "preferexternal" attribute cannot be recognized by the system. The API level must be at least 8.

In addition, two values can be set for Android: installlocation. the method defined in <mainfest> is as follows:

Android: installlocation = "Auto"

Android: installlocation = "preferexternal"

If you change to "Auto", it will be installed in the built-in memory of the mobile phone by default, but the program will also be based on the best location of the mobile phone, if the mobile phone memory is low and an SD card exists, the system determines the location to be installed.

Running result:

 

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.