How to get ACTION_ATTACH_DATA image

Asked

Viewed 38 times

0

I wish I could fix this problem that I am, well come on, I’m making a simple Wallpapers app, which has its own online image gallery, the app is practically finished the problem now is, i want my app to grab images from the gallery also but without being via Internet, those that open the manager, on android have the options in the share(share) gallery and use as/set as (set as) so far all right, look at the image below, inserir a descrição da imagem aqui

This image is the gallery application of Google Photos, in the 3 points of the upper corner there is a menu of options(PHOTO BELOW):

inserir a descrição da imagem aqui

As soon as clicking on "use as" appears the options:

inserir a descrição da imagem aqui

I managed to make my application appear in this "set as"

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

My problem is how do I receive this attach_data/image in my Activity ?

I did something similar, but instead of using :

<action android:name="android.intent.action.ATTACH_DATA" />

I used <action android:name="android.intent.action.SEND" /> but send is for sharing, I wanted something more specific so I tried to use attach_data, with send I managed to get the image my main Activity was like this:

public class SetWpfora extends AppCompatActivity {

    ImageView imageView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_set_wpfora);
        imageView = findViewById(R.id.imageVisualizer);

        Intent intent = getIntent();
        String action = intent.getAction();
        String type = intent.getType();

        if (Intent.ACTION_SEND.equals(action) && type != null) {
            if (type.startsWith("image/")) {
                handleSendImage(intent); // Handle single image being sent
            }
        }
    }

    public void handleSendImage(Intent intent) {
        Uri imageUri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
        if (imageUri != null) {
            Picasso.with(getApplicationContext())
                    .load(imageUri)
                    .into(imageView);
        }
    }
}

1 answer

1


After spending almost all day searching I got the resolution to the problem so simple but hard to find, to get the image I needed only that line:

Uri imageUri = getIntent().getData();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.