0

I use Android 11, target is:

compileSdkVersion 31
defaultConfig {
applicationId "com.pro.prowh"
minSdkVersion 24
targetSdkVersion 31
versionCode 16
versionName "22.01.12"
}

In the Manifest, I use:

< uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
< uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:ignore="ScopedStorage" />

MyApp create folder /storage/emulated/0/Documents/PRO_WH/ : OK
If erase PRO_WH folder, by any App, MyApp auto recarete it : OK

MyApp create a file test.txt inside PRO_WH, as /storage/emulated/0/Documents/PRO_WH/test.txt : OK
( this file never create before )
MyApp re-create a file test.txt with new content : OK
MyApp erase file test.txt : OK
MyApp re-create a file test.txt with new content : OK

Issuse:
If erase file test.txt by other app, example use File Manager, MyApp can't create file test.txt again. Error (IOException):

/storage/emulated/0/Documents/PRO_WH/test.txt: open failed: EEXIST (File exists)

file test.txt does not realy exist.

I need help :

How to resolver above isssue ?
or
How to re-create file if the file eraseed by other app ?

quanlevan
  • 33
  • 6

2 Answers2

0

It can be that the MediaStore is unaware of the delete and hence there is still an entry for the file in it's database.

If there is still an entry you can not create a file with the same path and name.

Maybe a reboot solves this by an automatic rescan.

You can query the mediastore for DISPLAY_NAME and RELATIVE_PATH to see

blackapps
  • 8,011
  • 2
  • 11
  • 25
0

Check it if file already exists then you can directly write on that file.

Android; Check if file exists without creating a new one

  • I know your answer, thanks ! But my issue is : MyApp can create file, and earese it, mny times. If this file erased by OTHER APP, MyApp don't re-create it. – quanlevan Jan 15 '22 at 04:07