最終更新:
moonlight_aska 2011年07月30日(土) 09:20:24履歴
インテント(Intent)を利用することで, ギャラリーを呼び出して端末内の画像の一覧を表示することができる.

(出典:Android版「美人時計」より)

(出典:Android版「美人時計」より)
- ImageView.java
- Intentのインスタンスを生成する.
- Intent#setTypeメソッドで, 画像全般("image/*")を指定する. jpegに限定する場合は, "image/jpeg"と指定.
- Intent#setActionメソッドで, Intent.ACTION_PICKを指定する.
- startActivityメソッドで, インテント呼出しする.
package com.moonlight_aska.android.imageview;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class ImageView extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// ギャラリー呼び出し
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_PICK);
startActivity(intent);
}
}
コメントをかく