如何调用android本地图库:
使用Intent实现页面跳转,到本地图库界面(如点击按钮bt1实现页面跳转至图库):
public void bt1(View view){
<span style="white-space:pre"> </span> Intent intent = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent,0);
<span style="white-space:pre"> </span>}
然后获取点击图片的路径:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(data!=null){
if(requestCode==0&&resultCode==Activity.RESULT_OK){
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 picPath = cursor.getString(columnIndex);
cursor.close();
if(picPath.equals("")) return;
Intent intent = new Intent(this, Function1.class);
Bundle bundle =new Bundle();
bundle.putString("imagePath",picPath);
intent.putExtras(bundle);
startActivity(intent);
}
}
把图片的路径通过Bundle进行传递给其他Activity并显示:
Intent intent =getIntent();
Bundle bundle =intent.getExtras();
String imagePath=bundle.getString("imagePath");
bitmap =BitmapFactory.decodeFile(imagePath);
<span style="white-space:pre"> </span>mImageView.setImageBitmap(bm);