我得到了答案:)
这可以通过以下方式使用Intent来完成:
Intent intent = getIntent();
// Get the action of the intent
String action = intent.getAction();
// Get the type of intent (Text or Image)
String type = intent.getType();
// When Intent's action is 'ACTION+SEND' and Tyoe is not null
if (Intent.ACTION_SEND.equals(action) && type != null) {
if (type.startsWith("image/")) { // When type is 'image/*'
handleSendImage(intent); // Handle single image being sent
}
}
private void handleSendImage(Intent intent) {
// Get the image URI from intent
Uri imageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
// When image URI is not null
if (imageUri != null) {
// Update UI to reflect image being shared
view_news.setImageURI(imageUri);
news.setVisibility(View.GONE);
} else{
Toast.makeText(this, "Error occured, URI is invalid", Toast.LENGTH_LONG).show();
}
}
这解决了我从图库中获取图像并在“兴趣”应用程序中的图像视图中显示图像的问题。
谢谢:)