how can I access Picasso' s cached image to make a share intent?

I hope you can understand my question :-)

Sorry for my delay, I found a solution, but, not a good one...

First, I really searched for a while and looked at the code of Picasso. It seems like you should provide your own downloader and other stuff. But then, why should I use the lib...

And then, I suppose it's Picasso's design / architecture to just cache the file in the internal storage. Maybe because the external storage is not always available (like the user may plug in his SD card to his computer), or maybe because the external storage is not as fast as the internal... That's my guess. In a word, other apps cannot access the internal storage of the current app, so the share cannot be done.

Thus, I made a really ordinary solution. I just wait for Picasso to give the Bitmap, and compress it to a file in the external file, then do the share. It seems like a bad solution, but it really solves the problem, yes...

You should be aware of whether the external cache directory is available or not. If not, you cannot do the share. And you need to put the compress task in a background thread, so, waiting the external file cached... Does it seem like a bad solution? I think so...

Below is my project code, you can have a try...

private boolean mSaved; // a flag, whether the image is saved in external storage
private MenuItem mShare;
private Intent mIntent;
private ShareActionProvider mShareActionProvider;
private File mImage; // the external image file would be saved...


private Target target = new Target() {
    @Override
    public void onBitmapLoaded(final Bitmap bitmap, Picasso.LoadedFrom from) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                FileOutputStream os = null;
                try {
                    String dir = CatnutUtils.mkdir(getActivity(), Constants.FANTASY_DIR); // check the exteral dir avaiable or not...
                    String[] paths = Uri.parse(mUrl).getPath().split("/");
                    mImage = new File(dir + File.separator + paths[2] + Constants.JPG); // resoleve the file name
                } catch (Exception e) { // the external storage not available...
                    Log.e(TAG, "create dir error!", e);
                    return;
                }
                try {
                    if (mImage.length() > 10) { // > 0 means the file exists
                        // the file exists, done.
                        mIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(mImage));
                        mSaved = true;
                        return;
                    }
                    os = new FileOutputStream(mImage);
                    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, os);
                    mIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(mImage));
                    mSaved = true;
                } catch (FileNotFoundException e) {
                    Log.e(TAG, "io error!", e);
                } finally {
                    if (os != null) {
                        try {
                            os.close();
                        } catch (IOException e) {
                            Log.e(TAG, "io closing error!", e);
                        }
                    }
                }
            }
        }).start();
        mFantasy.setImageBitmap(bitmap);
    }
@Override
    public void onBitmapFailed(Drawable errorDrawable) {
        mFantasy.setImageDrawable(errorDrawable);
    }

    @Override
    public void onPrepareLoad(Drawable placeHolderDrawable) {
        if (placeHolderDrawable != null) {
            mFantasy.setImageDrawable(placeHolderDrawable);
        }
    }
};

@Override
public void onPrepareOptionsMenu(Menu menu) {
    mShare.setEnabled(mSaved);
}

public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.fantasy, menu);
    mShare = menu.findItem(R.id.action_share);
    mShareActionProvider = (ShareActionProvider) mShare.getActionProvider();
    mShare.setActionProvider(mShareActionProvider);

    mShareActionProvider.setShareIntent(mIntent);
}

Finally, call Picasso.with(getActivity()).load(mUrl).into(target);

When the file is saved, the user can click the share menu do the share.