Home > Software design >  Ancroid11 : My app does not re-create file if the file erased by other app
Ancroid11 : My app does not re-create file if the file erased by other app

Time:01-15

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 ?

CodePudding user response:

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

CodePudding user response:

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

Android; Check if file exists without creating a new one

  •  Tags:  
  • Related