我怎么可以访问毕加索的缓存形象做一个分享意图是什么? [英] how can I access Picasso' s cached image to make a share intent?

查看:150
本文介绍了我怎么可以访问毕加索的缓存形象做一个分享意图是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的毕加索,以帮助图像的缓存。

I' m using Picasso to help the cache of images.

现在的问题是,我怎么能访问下载的图像做一个分享意图是什么?

The question is, how can I access the downloaded image to make a share intent?

什么想法?谢谢!

推荐答案

我AP preciate你能明白我的问题: - )

I appreciate you can understand my question :-)

对不起,我的延迟,我是真的找到一个soluation,但不是一个好sulution ...

Sorry for my delay, I truely find a soluation, but, not a good sulution...

首先,我真的寻找了一会儿,看到毕加索的code,看来你应该提供自己的下载和其他的东西。因为它,我为什么要使用的lib ...

First, I really search for a while and see the code of Picasso, it seems you should provider your own downloader and other stuff. Since it, why should I use the lib...

然后,我想这是毕加索的设计架构,只是缓存在内部存储器中的文件,可能是外部stotage并不总是可用(如用户可插件他SD卡到他的电脑),或外部存储无以最快的速度INTERAL ......我猜。总之,其他应用程序无法访问应用程序的内部存储,这样的比例不能这样做。

And then, I suppose it' s picasso' s design architecture, just cache the file in internal storage, may be the external stotage not always available(like the user may plugin his sdcard to his computer), or the external storage no as fast as the interal... I guess. In a word, other app cannot access the internal storage of the app, so the share cannot be done.

由于它,我做了一个非常oridinary的解决方案,只是在等待毕加索给我们位图,和COM preSS到一个文件中的外部文件和然后做份额。它的似乎是一个坏的解决方案,但它确实求解带的问题,是的......

Since it, I made a really oridinary solution, just waiting the picasso give us the Bitmap, and compress it to a file in the external File and then do the share. It' s seems a bad solution, but it really sovle the problem, yes...

您应该知道是否有外部缓存目录可用与否,如果不是,你不能做的份额。你需要把玉米preSS在后台线程,因此,等待外部文件的缓存...这似乎不好解决?我想是这样...

You should be aware whether the external cache dir available or not, if not, you cannot do the share. And you need to put the compress in a background thread, so, waiting the external file cached... It seems bad solution? I think so...

下面是我的项目code,可以哈瓦一试...

below it' s my project code, you can hava 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);
}

最后 Picasso.with(getActivity())负载(mUrl)。走进(目标);

该文件保存时,canclick共享菜单中的用户做的份额。

when the file saved, the user canclick the share menu do the share.

这篇关于我怎么可以访问毕加索的缓存形象做一个分享意图是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆