Display jpg image from intent in imageview

2019-02-26 01:17发布

How to display an Image received from an "android.intent.action.SEND" in an imageview? The user selects my app from the list of apps to share an image. The image is sent via intent and my activity opens up but how to use this image in an imageview?

using

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

does not help and

getIntent().getType() returns image/jpg

3条回答
Explosion°爆炸
2楼-- · 2019-02-26 01:51

You are receving Image in Intent, So you have to update your Manifest as:

<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

Then Activity needs:

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);
        }
    }
.
.
.
查看更多
不美不萌又怎样
3楼-- · 2019-02-26 01:57

Bitmap implements Parcelable interface. So to pass it use

intent.putExtra("bitmap", bitmap);

and to retrieve it use:

Bitmap bitmap = (Bitmap) intent.getParcelableExtra("bitmap");

and use ImageView.setImageBitmap().

EDIT: see Receiving Content from Other Apps

查看更多
Summer. ? 凉城
4楼-- · 2019-02-26 02:07

Try this

 BitMap thumnail= (Bitmap) getIntent().getExtras().getParcelable("data");
 yourImageViewId.setImageBitmap(receiptimage);

Hope it helps

查看更多
登录 后发表回答