▼Androidメモ▼
SDカードへのアプリ保存


SDカードへのアプリ保存を行うプログラムを作成する。



ソースコード
InstallLocationEx.java
package net.npaka.installlocationex;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Window;
import android.widget.LinearLayout;
import android.widget.TextView;

//SDカードへのインストール(AndroidManifest.xmlで設定)
public class InstallLocationEx extends Activity {
    private final static int WC=LinearLayout.LayoutParams.WRAP_CONTENT;
    //初期化
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        requestWindowFeature(Window.FEATURE_NO_TITLE);

        //レイアウトの生成
        LinearLayout layout=new LinearLayout(this);
        layout.setBackgroundColor(Color.rgb(255,255,255));
        layout.setOrientation(LinearLayout.VERTICAL);
        setContentView(layout); 
        
        //テキストビューの生成
        TextView textView=new TextView(this);
        textView.setText("InstallLocationEx");
        textView.setTextSize(16.0f);                  
        textView.setTextColor(Color.rgb(0,0,0));
        textView.setLayoutParams(new LinearLayout.LayoutParams(WC,WC));
        layout.addView(textView);
    }  
}

AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="net.npaka.installlocationex"
    android:versionCode="1"
    android:versionName="1.0"
    android:installLocation="preferExternal">
    <application 
        android:icon="@drawable/icon" 
        android:label="@string/app_name">
        <activity 
            android:name=".InstallLocationEx"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
    <uses-sdk android:minSdkVersion="8" />

</manifest> 



−戻る−