Reputation: 377
i have been making an app which download files from internet and save themon storage i have 2 questions :first how to address it to save them in downlod folder which is the exact address? and second where is this "/data/user/0/com.example.moein.download_kotlin/files/Downloads/file.jpg" directory that it is using now? here is my code
mainFetch = Fetch.Builder(applicationContext, "Download 1 file")
.setDownloadConcurrentLimit(1) .
.enableLogging(true)
.build()
//Single enqueuing example
val request = Request("https://www.sample-videos.com/img/Sample-jpg-image-50kb.jpg",
applicationContext.getFilesDir().getPath().toString() +"/Downloads/file.jpg")
request.priority=Priority.HIGH;
request.networkType=NetworkType.ALL
request.addHeader("download", "2")
mainFetch!!.enqueue(request, object : Func<Download> {
override fun call(t: Download) {
Toast.makeText(applicationContext,t.file,Toast.LENGTH_SHORT).show();
//toasts /data/user/0/com.example.moein.download_kotlin/files/Downloads/file.jpg
}
}, object : Func<Error> {
override fun call(t: Error) {
Toast.makeText(applicationContext,t.toString(),Toast.LENGTH_SHORT).show();
}
})`
Upvotes: 2
Views: 1572
Reputation: 24907
first how to address it to save them in downlod folder which is the exact address?
Use following:
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
If you are targetting Andrpid 6.0 and above, remember to request for WRITE_EXTERNAL_STORAGE
to write to this directory and READ_EXTERNAL_STORAGE
to read from this directory. User needs to grant these permissions,hence you have to implement permission model. You can follow this official tutorial to implement this.
second where is this "/data/user/0/com.example.moein.download_kotlin/files/Downloads/file.jpg" directory that it is using now?
This is your application-specific directory. Files saved to this are private to your app, and other apps cannot access them (nor can the user, unless they have root access). This makes internal storage a good place for internal app data that the user doesn't need to directly access.
However I found on Samsung device that ES file explorer can access this directory. But its a mystery how they manage to do it.
Upvotes: 2