看不到图像已保存到我的内部存储器

时间:2020-07-08 10:58:09

标签: java android picasso android-storage

我试图在本地保存图像,但是当我使用设备资源管理器并导航到NewVisionARDirectory时。我似乎看不到它。这是保存的/data/user/0/com.xxx.xxxx/app_NewVisionARDirectory

图像的路径

我正在使用Picasso将下载的图像从URL更改为Bitmap

以下是我用于在设备上本地保存URL图像的代码:

try {

                    @SuppressLint("DefaultLocale") String fileName = String.format("%d.jpg", System.currentTimeMillis());

                    FileOutputStream fos = null;
                    try {
                        Bitmap bitmap = Picasso.get().load(MyUrl).get();

                        //Saving the Image Internally.
                        ContextWrapper cw = new ContextWrapper(context);
                        // path to /data/data/yourapp/app_data/imageDir

                        File directory = cw.getDir("NewVisionARDirectory", Context.MODE_PRIVATE);

                        Toast.makeText(context, "" + directory, Toast.LENGTH_LONG).show();
                        File mypath = new File(directory, fileName);

                        fos = new FileOutputStream(mypath);
                        // Use the compress method on the BitMap object to write image to the OutputStream
                        bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fos);

                        System.out.println("----- Bitmap path -- " + bitmap);
                        fos.flush();
                        fos.close();

                        Toast.makeText(context, "Seems working ....", Toast.LENGTH_LONG).show();




                    } catch (IOException e) {
                        e.printStackTrace();
                        Toast.makeText(context, "Something wrong" + e, Toast.LENGTH_LONG).show();
                    } finally {
                        try {
                            fos.close();
                        } catch (IOException e) {
                            e.printStackTrace();
                            Toast.makeText(context, "Something wrong" + e, Toast.LENGTH_LONG).show();
                        }
                    }
                } catch (Exception e) {
                }
                return null;
            }

此代码中我缺少什么?下面是设备文件管理器的路径图像 enter image description here

0 个答案:

没有答案