I tried out the library and it's not working.
Here's my code
class MainActivity : AppCompatActivity() {
// fetchListener code, removed, for the sake of brevity.
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val url = "http://www.alexszepietowski.com/wp-content/uploads/downloads/2013/03/The%202%20Golden%20Rules%20of%20Property,%20Business%20and%20Life!.pdf"
val fileName = "MyFile.pdf"
val dirPath = "/FileDownloader/PDF/$fileName"
val fetchConfiguration = FetchConfiguration.Builder(this)
.setDownloadConcurrentLimit(3)
.build()
val fetch = Fetch.getInstance(fetchConfiguration)
val request = Request(url, dirPath)
request.priority = Priority.HIGH
request.networkType = NetworkType.ALL
request.addHeader("clientKey", "SD78DF93_3947&MVNGHE1WONG")
fetch.addListener(fetchListener)
fetch.enqueue(request)
}
fun Log(msg: String) {
android.util.Log.d("MainActivity", msg)
}
}
AndroidManifest.xml
<manifest
... >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
...>
...
</application>
</manifest>
Log output
D: FetchListener. onError. Error = UNKNOWN_IO_ERROR, Download = DownloadInfo(id=-1721883501, namespace='LibGlobalFetchLib', url='http://www.alexszepietowski.com/wp-content/uploads/downloads/2013/03/The%202%20Golden%20Rules%20of%20Property,%20Business%20and%20Life!.pdf', file='/FileDownloader/PDF/MyFile.pdf', group=0, priority=HIGH, headers={clientKey=SD78DF93_3947&MVNGHE1WONG}, downloaded=0, total=-1, status=FAILED, error=UNKNOWN_IO_ERROR, networkType=ALL, created=1536016053913, tag=null, enqueueAction=REPLACE_EXISTING, identifier=0, downloadOnEnqueue=true, extras={})
you can check out my full code here -> https://github.com/Edge-Developer/FetchDownloadManagerIssue
val dirPath = "/FileDownloader/PDF/$fileName" looks incorrect.
Try something like context.getCacheDir() and append your dir path.
please type out a sample code
D/LibGlobalFetchLib: DownloadManager starting download DownloadInfo(id=-94132710, namespace='LibGlobalFetchLib', url='http://www.alexszepietowski.com/wp-content/uploads/downloads/2013/03/The%202%20Golden%20Rules%20of%20Property,%20Business%20and%20Life!.pdf', file='/data/user/0/com.edgedevstudio.fetchdownloadmanagerissue/cache/FileDownloader/PDF/MyFile.pdf', group=0, priority=HIGH, headers={clientKey=SD78DF93_3947&MVNGHE1WONG}, downloaded=0, total=-1, status=QUEUED, error=NONE, networkType=ALL, created=1536090340704, tag=null, enqueueAction=REPLACE_EXISTING, identifier=0, downloadOnEnqueue=true, extras={})
D/LibGlobalFetchLib: FileDownloader starting Download DownloadInfo(id=-94132710, namespace='LibGlobalFetchLib', url='http://www.alexszepietowski.com/wp-content/uploads/downloads/2013/03/The%202%20Golden%20Rules%20of%20Property,%20Business%20and%20Life!.pdf', file='/data/user/0/com.edgedevstudio.fetchdownloadmanagerissue/cache/FileDownloader/PDF/MyFile.pdf', group=0, priority=HIGH, headers={clientKey=SD78DF93_3947&MVNGHE1WONG}, downloaded=0, total=-1, status=QUEUED, error=NONE, networkType=ALL, created=1536090340704, tag=null, enqueueAction=REPLACE_EXISTING, identifier=0, downloadOnEnqueue=true, extras={})
D/MainActivity: FetchListener. onStarted
D/MainActivity: FetchListener. onDownloadBlockUpdated
D/MainActivity: FetchListener. onDownloadBlockUpdated FetchListener. onProgress
D/MainActivity: FetchListener. onCompleted
i mean, actual code NOT log output
The commit is the code, I will paste here for you.
val dirPath = "$cacheDir/FileDownloader/PDF/$fileName"
thanks man, i'm about to try it out
hey, it did indicate that file was successfully downloaded but i am unable to find the actual downloaded file.
I've use file explorer and found nothing
Good fetch is working.
Cache directory is a sandboxed directory in your application folder. I used this example because sandboxed directories do not require PERMISSIONS to write to it. Just so you know cache directory can be found at /Android/data/.
I rewrote your sample app to request permissions and write to the root DOWNLOAD folder like you are expecting.
Thanks very much!
So helpful
It worked!
Most helpful comment
Good fetch is working.
Cache directory is a sandboxed directory in your application folder. I used this example because sandboxed directories do not require
PERMISSIONSto write to it. Just so you know cache directory can be found at/Android/data/.I rewrote your sample app to request permissions and write to the root
DOWNLOADfolder like you are expecting.https://github.com/sethchhim/FetchDownloadManagerIssue/commit/c083874844ca9f6949f749b2b004eac7f8f7aedf