0

Android Q could not create file on public directory.

is there has any way to make nomedia file on public directory?

without below code

android:requestLegacyExternalStorage="true"

or is there has any way to hide media file on gallery

thank you.

sun
  • 13
  • 4
  • What is public directory? – blackapps Dec 03 '19 at 16:34
  • @blackapps File.getExternalStoragePublicDirectory is deprecated. but downloadmanager can do that with some limit. it allowed some directory like DIRECTORY_DOWNLOADS DIRECTORY_PICTURES – sun Dec 04 '19 at 11:26

1 Answers1

0

i solved it using download manager easily.

just download empty file from web.

this is my sample code

val downloadManager = context.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
val request = DownloadManager.Request(Uri.parse("https://www.example.com/.nomedia"))
        .setTitle(".nomedia")
        .setDestinationInExternalPublicDir(Environment.DIRECTORY_DCIM, "/test/.nomedia") 
        .setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI or DownloadManager.Request.NETWORK_MOBILE)
        .setAllowedOverMetered(true) 
        .setAllowedOverRoaming(false)
downloadManager.enqueue(request)
sun
  • 13
  • 4