Android 显示错误消息 } } @凌驾 公共void onClick(视图){ //如果单击的按钮为,请选择 如果(视图==按钮选择){ showFileChooser(); } //如果单击的按钮是上载 else if(视图==按钮加载){ 上传文件(); } } }

Android 显示错误消息 } } @凌驾 公共void onClick(视图){ //如果单击的按钮为,请选择 如果(视图==按钮选择){ showFileChooser(); } //如果单击的按钮是上载 else if(视图==按钮加载){ 上传文件(); } } },android,picasso,firebase-storage,Android,Picasso,Firebase Storage,我通常看到人们在Firebase数据库中保存DownloadUrl变量,但您也可以将其保存在SQL数据库中 无论您在哪里保存您的下载URL,都可以在毕加索中使用它,如下所示: Picasso.with(getActivity()) .load(imageUrl) .networkPolicy(NetworkPolicy.OFFLINE) .into(imageView, new Callback() { @Override public void onSuccess() {

我通常看到人们在
Firebase数据库中保存DownloadUrl变量,但您也可以将其保存在SQL数据库中

无论您在哪里保存您的下载URL,都可以在
毕加索中使用它,如下所示:

Picasso.with(getActivity())
.load(imageUrl)
.networkPolicy(NetworkPolicy.OFFLINE)
.into(imageView, new Callback() {
    @Override
    public void onSuccess() {

    }

    @Override
    public void onError() {
        //Try again online if cache failed
        Picasso.with(getActivity())
                .load(posts.get(position).getImageUrl())
                .error(R.drawable.header)
                .into(imageView, new Callback() {
            @Override
            public void onSuccess() {

            }

            @Override
            public void onError() {
                Log.v("Picasso","Could not fetch image");
            }
        });
    }
});
其中
networkPolicy(networkPolicy.OFFLINE)
将强制毕加索首先在硬盘中查找它。在清除缓存的情况下,
毕加索将在线查找

Picasso
将您的图像保存在以下路径中(例如Emulator):

/data/data/com.example.myapp/cache/picasso cache

一旦
毕加索
将您的图像保存在缓存中,我不知道如何在不使用
毕加索
的情况下访问图像

您还可以使用
DownloadManager
将图像下载到缓存目录中。其中(String
destinationDirectory=getContext().getCacheDir().getPath().toString()

下载图像后,必须保存新的图像路径。
我希望有帮助

您想下载应用文件夹中的图像还是激活毕加索中的缓存?如果你想激活毕加索的缓存,那么你可以在这里找到一些有用的信息:@Blehi yeah thanx获取信息,如果你能帮助我完成实现步骤,那就太好了
Picasso.with(getActivity())
.load(imageUrl)
.networkPolicy(NetworkPolicy.OFFLINE)
.into(imageView, new Callback() {
    @Override
    public void onSuccess() {

    }

    @Override
    public void onError() {
        //Try again online if cache failed
        Picasso.with(getActivity())
                .load(posts.get(position).getImageUrl())
                .error(R.drawable.header)
                .into(imageView, new Callback() {
            @Override
            public void onSuccess() {

            }

            @Override
            public void onError() {
                Log.v("Picasso","Could not fetch image");
            }
        });
    }
});
private void downloadFile(Context context, final String fileName, final String fileExtension, String destinationDirectory, String url) {

        BroadcastReceiver onComplete;

        DownloadManager downloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);

        Uri uri = Uri.parse(url);

        DownloadManager.Request request = new DownloadManager.Request(uri);

        request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
        request.setDestinationUri(Uri.fromFile(new File(destinationDirectory,fileName + fileExtension)));
        request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE);

        onComplete = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                String action = intent.getAction();
                if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {

                    //DO WHATEVER YOU NEED AFTER FILE HAS BEEN DOWNLOADED HERE

                }

            }
        };

        getActivity().registerReceiver(onComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));

        downloadManager.enqueue(request);


    }