android - 在 imageview 中显示来自 Intent 的 jpg 图像

标签 android android-intent

如何在 imageview 中显示从 "android.intent.action.SEND" 接收到的图像? 用户从应用程序列表中选择我的应用程序来共享图像。图像通过 Intent 发送并且我的 Activity 打开,但如何在 ImageView 中使用此图像?

使用

Bitmap  thumbnail = (Bitmap) getIntent().getExtras().get("data");

没有帮助并且

getIntent().getType() returns image/jpg

最佳答案

您正在 Intent 中接收图像,因此您必须将 list 更新为:

<activity android:name=".Your_Activity" >
    ...
    ...
    <intent-filter>
    ...
        <action android:name="android.intent.action.SEND" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:mimeType="image/*" />
    </intent-filter>
</activity

那么Activity需要:

void onCreate (Bundle savedInstanceState) {
...
// Get intent, action and MIME type
Intent intent = getIntent();
String action = intent.getAction();
String type = intent.getType();

if (Intent.ACTION_SEND.equals(action) && type != null) {
    if (type.startsWith("image/")) {
        Uri imageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
        if (imageUri != null) {
            YourImageView.setImageUri(imageUri);
        }
    }
.
.
.

关于android - 在 imageview 中显示来自 Intent 的 jpg 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11590881/

相关文章:

android - 在 Android 中随机启动 Activity

java - 单击按钮时更改 xml 页面中的图像.. android

android - 带系统 : A resource failed to call release. flutter

java - Android Material Design 抽屉导航 setClickListener

android - 从相机中选取图像时无法提供结果,但从图库中选取图像时没有问题

Android:如何确认邮件发送成功

android - 将字符串从服务传递到 Intent

android - 通过 events.dtend 更新日历 instances.end

android - 从互联网下载 Android 布局

java - ANDROID 使用分享 Intent 分享到 Facebook、Twitter 等