0

This is my question.

First I have create my personal folder on create

File parentFolder = new File(MainApplication.getInstance().getExternalCacheDir().getAbsolutePath()
            + File.separator+"myfolder");
    if (!parentFolder.exists()) {
        parentFolder.mkdirs();
    }

Second in my application,i can receive file such as png from another application,and the file that i received has been saved in /Android/data/packageName/cache/myfolder/hashcode/example.png. And i choose the gallery to open it from intent chooser.

When gallery is open and I can see the png file.I kill my application's process and uninstall it.

Finally I install my application again.The path /Android/data/packageName doesn't been created! And create function show that

MainApplication.getInstance().getExternalCacheDir();

returns null!

Give me some advise! Thank you.

1 Answers1

1

Try using

new Context().getApplicationContext().getExternalCacheDir().getAbsolutePath()
repeat
  • 18,496
  • 4
  • 54
  • 166
rusted brain
  • 1,052
  • 10
  • 23
  • This method is not used. No matter how to getExternalCacheDir() will return null.Because app does not create path for some reason – user3526542 Aug 20 '15 at 09:55
  • So instead of cache you can use the file folder/directory. Anyways cache folder will delete its files automatically when device is on low storage. – rusted brain Aug 20 '15 at 10:00
  • i know it ,but i need to delete the files and folders i received or created at onDestroy() – user3526542 Aug 20 '15 at 12:00