我从画廊拍了一张图片,我想在另一堂课上使用它。是否可以使用“uri”?
Uri selectedImage = data.getData();
String path = selectedImage.getPath();
Intent sintent = new Intent(FromFile.this, OurView.class);
startActivity(sintent);
在创建意图后添加它。
sintent.putExtra("image", path);
在 OurView 通话中
String path = getIntent().getStringExtra("image");
您可以将Uri
要发送的图像放在发送者的意图中Activity
。像这样的东西:
Intent sintent = new Intent(FromFile.this, OurView.class);
intent.putExtra("selectedImage", selectedImage.toString());
startActivity(sintent);
Activity
然后要检索它,请在被调用的代码中使用此代码:
//Where OurView is assumed to be the class name of your Activity that is being called
Uri selectedImage = Uri.parse(OurView.this.getIntent().getExtras().getString("selectedImage"));
1)如果您想将路径传递给下一个活动。尝试这个 -
Intent sintent = new Intent(FromFile.this, OurView.class);
sintent.putExtra("pathvalue", path);
startActivity(sintent);
在 nextActivity(OurView.java) -
String path = getIntent().getStringExtra("image");
2)如果你想将 Uri 传递给下一个 Activity。尝试这个 -
Uri selectedImage = data.getData();
String path = selectedImage.getPath();
Intent intent = new Intent(FromFile.this, OurView.class);
intent.setData(Uri.parse(selectedImage));
startActivity(intent);
在 nextActivity(OurView.java) -
Uri selectedImage = getIntent().getData();