准备
ImageView imagespace;
int RESULT_LOAD_IMAGE;
启动意图
protected void onCreate(Bundle savedInstanceState) {
imagespace.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent imageIntent = new Intent(Intent.ACTION_GET_CONTENT);
imageIntent.setType("image/*");
startActivityForResult(imageIntent,RESULT_LOAD_IMAGE);
Snackbar.make(view,"here",Snackbar.LENGTH_SHORT).show();
}
});
}
接受并打开图库
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK) {
Uri returnImageUri = data.getData();
Log.v("TAG", returnImageUri.toString());
Toast.makeText(getApplicationContext(),"图片位置:"+returnImageUri.toString(),Toast.LENGTH_SHORT).show();
imagespace.setImageURI(returnImageUri);
}
}