gpt4 book ai didi

android - 通过 Intent 将图库图像传递给另一个 Activity

转载 作者:行者123 更新时间:2023-11-29 15:19:20 25 4
gpt4 key购买 nike

我需要使用该图像的路径将图像从画廊发送到另一个 Activity ,但没有任何反应......帮帮我......这是代码..

        protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if(requestCode==RESULT_LOADIMAGE&&resultCode==RESULT_OK&&null!=data)
{
Uri selectedImages=data.getData();
String[] filePathColon={MediaStore.Images.Media.DATA};
Cursor cursr=getContentResolver().query(selectedImages, filePathColon, null, null, null);
cursr.moveToFirst();
int columnindex=cursr.getColumnIndex(filePathColon[0]);
String picturepath=cursr.getString(columnindex);
cursr.close();

Intent intent= new Intent(MainActivity.this,SecondActivity.class);
intent.putExtra("imagePath",filePathColon );
startActivity(intent);

}
}

第二个 Activity 代码是

    protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
img=(ImageView)findViewById(R.id.imageView1);


getData();

}

private void getData(){
String ps=getIntent().getStringExtra("imagepath");

img.setImageBitmap(BitmapFactory.decodeFile(ps));

}

最佳答案

intent.putExtra("imagePath",filePathColon );

应该是

intent.putExtra("imagePath",picturepath);

因为 filepathcolon 指的是列索引而 picturepath 指的是 URI

并使用它

String ps=getIntent().getStringExtra("imagePath"); //it should be same as you send it

关于android - 通过 Intent 将图库图像传递给另一个 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20244559/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com