Androidはインストール書き換えを作成してSDカードAPP 2 SDに移行


/**********************************************************
皆さんご存知のようにブログを書くのは疲れると思います.
転載は出典を明記してください.http://blog.csdn.net/ta893115871
あなたのマウスを可哀想にしないでください(*^^*)ヒヒ…
*************************************************************/
SDK 2.2がリリースされる前に、Androidインストールアプリは携帯電話のメモリにしかインストールできず、限られたリソースの下で、せいぜい50~100セットのプログラムをインストールすることができ、「Angry Brid」の怒った小鳥を携帯電話にインストールすれば.では
そして知った.
プログラムをインストールしているときにSDカードがあることを発見すると、自動的にSDカードにインストールされ、ない場合はボタンイベントを通じて、アプリケーション設定に進み、UserがアプリケーションをSdカードに移動するか、またはプログラムをSDカードから携帯電話に戻すかを決定する.
.javaファイル
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
			//      ,        , User            Sd 
				startActivity(new Intent("android.intent.action.MANAGE_PACKAGE_STORAGE"));
			}
		});
    }


    
}

AndroidManifest.xml
このプログラムの鍵はAndroid Mainfest.xmlの Android:installLocation=「preferExternal」という属性です.プログラムをデフォルトでSDカードにインストールするpreferExternalに設定します.もう一つのポイントは、本プログラムのAPIです  Levelはandroid:minSdkValersonが「8」以上のバージョンを作成する必要があります.
<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>

 
古いSDKバージョンでandroid:minSdkValersonが8未満であれば、Android Mainfest.xmlに直接追加します. Android:installLocation=「preferExternal」プロパティ、結果はどうなりますか?
システムが認識できない Android:installLocation=「preferExternal」という属性です.APIレベルは少なくとも8以上でなければなりません.
また、 Android:installLocationでは2つの値を設定できますが、で定義する方法は以下の通りです.
  android:installLocation="auto"
  android:installLocation="preferExternal"
「auto」に変更すると、携帯電話の内蔵メモリにデフォルトでインストールされますが、プログラムは携帯電話の最適な位置に基づいて、携帯電話のメモリが低く、Sdカードが存在することを発見すると、インストールする場所を決定するシステムがあります.
実行結果:
Android 制定安装重写迁移至SD卡 APP2SD_第1张图片 Android 制定安装重写迁移至SD卡 APP2SD_第2张图片