How to get ACTION_ATTACH_DATA image

0
I would like to be able to remedy this problem that I am, well let's go, I'm making a simple Wallpapers app, which has its own image gallery online, the app is pretty much completed the problem now is, I want my app to get images of the gallery also however without being via intent, those that open the manager, in android have the options in the gallery of share and use it as / set as (set as) so far so good, look at the image below,

ThisimageistheGooglePhotosgalleryapplication,inthetop3pointsthereisamenuofoptions(PHOTOBELOW):

Onceyouclickon"use as" the following options appear:

Iwasabletomakemyapplicationappearinthis"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 get this attach_data / image in my activity?

I did something similar, but instead use:

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

I used <action android:name="android.intent.action.SEND" /> but the send is for sharing, I wanted something more specific so I tried to use attach_data, with the send I was able to get the image my main activity looked 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);
        }
    }
}
    
asked by anonymous 11.04.2018 / 20:25

1 answer

1

After spending almost all day researching I got the resolution for the problem so simple but difficult to find, to get the image I just needed this line:

Uri imageUri = getIntent().getData();
    
11.04.2018 / 21:48