0

我从画廊拍了一张图片,我想在另一堂课上使用它。是否可以使用“uri”?

Uri  selectedImage = data.getData();
String path = selectedImage.getPath();

Intent sintent = new Intent(FromFile.this, OurView.class);
startActivity(sintent);
4

3 回答 3

1

在创建意图后添加它。

sintent.putExtra("image", path);

在 OurView 通话中

String path = getIntent().getStringExtra("image");
于 2012-07-23T14:01:18.103 回答
0

您可以将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"));
于 2012-07-23T14:01:59.327 回答
0

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();
于 2012-07-23T14:04:30.467 回答