[英]How can i select an image from gallery and display that in another activity..?
i have created the code to select image from gallery,but i can not pass that value to another activity through bundle..please help me 我已经创建了从图库中选择图像的代码,但是我无法通过捆绑软件将该值传递给另一个活动。请帮助我
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == SELECT_PICTURE) {
Uri selectedImageUri = data.getData();
selectedImagePath = getPath(selectedImageUri);
System.out.println("Image Path : " + selectedImagePath);
img.setImageURI(selectedImageUri);
enter code here
i need to pass the SelectedImageUri
to another activity as bundle 我需要将SelectedImageUri
作为捆绑包传递给另一个活动
Use this 用这个
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == SELECT_PICTURE) {
Uri selectedImageUri = data.getData();
selectedImagePath = getPath(selectedImageUri);
System.out.println("Image Path : " + selectedImagePath);
img.setImageURI(selectedImageUri);
Intent intent = new Intent(this , Second_activity.class );
intent.putExtra("image_path", selectedImagePath);
startActivity(intent);
}
it will start the Second Activity, then on the second Activity receive those values by this 它将启动第二个Activity,然后在第二个Activity上接收这些值
Bundle extras = getIntent().getExtras();
if (extras != null) {
String value = extras.getString("image_path");
//use value
}
I know is not exactly what you were looking for but if you pass selectedImagePath using i.putExtra("photoPath", selectedImagePath);
我知道不是您要找的东西,但是如果您使用i.putExtra("photoPath", selectedImagePath);
传递selectedImagePath i.putExtra("photoPath", selectedImagePath);
, you can later load the image using only the path. ,以后可以仅使用路径加载图像。
I need to pass the SelectedImageUri to another activity as bundle 我需要将SelectedImageUri作为捆绑包传递给另一个活动
=> FYI, Uri class itself implement Parcelable, so you can add and get value into/from Intent directly. =>仅供参考,Uri类本身实现了Parcelable,因此您可以直接向Intent添加值或从Intent获取值。
// Add a Uri instance to an Intent
intent.putExtra("SelectedImageUri", SelectedImageUri);
// Get a Uri from an Intent
Uri uri = intent.getParcelableExtra("SelectedImageUri");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.