权限
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"> </uses-permission> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
布局
<ImageView
android:id="@+id/img_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
</ImageView>
<Button
android:id="@+id/butt_11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="调用图库相册"
android:layout_gravity="center">
*/*//*//***********
定义
private static int RESULT_LOAD_IMAGE = 1;
//初始化
img_view= (ImageView) findViewById(R.id.img_view);
///控件
butt_11= (Button) findViewById(R.id.butt_11);
//方法
butt_11.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent=new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent,RESULT_LOAD_IMAGE);
}
});
******///*********************************************
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
Uri selectedImage = data.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
///相册选取
img_view.setImageBitmap(BitmapFactory.decodeFile(picturePath));
}
}