[英]passing gallery image to another activity through intent
I need to send a image from gallery to another activity by using the path of that image but nothing happened... help me out...... here is the code.. 我需要通过使用该图像的路径将图像从画廊发送到另一个活动,但是什么也没有发生……帮帮我……这是代码。
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);
}
}
and second activity code is 第二个活动代码是
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 );
should be 应该
intent.putExtra("imagePath",picturepath);
because filepathcolon refers to column index and picturepath refers to the URI 因为filepathcolon指向列索引,而picturepath指向URI
and get it using 并使用它
String ps=getIntent().getStringExtra("imagePath"); //it should be same as you send it
please change like this 请这样改变
Intent intent= new Intent(MainActivity.this,SecondActivity.class);
intent.putExtra("imagePath",picturepath);
startActivity(intent);
}
The two strings in your Intent do not match: You wrote imagePath with capital P in the first Activity, but not in your second one. Intent中的两个字符串不匹配:您在第一个Activity中用大写P编写了imagePath,但在第二个Activity中却写不了。
String ps=getIntent().getStringExtra("imagePath");
fixes it 修复它
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.