polcpp / nativescript-downloadmanager Goto Github PK
View Code? Open in Web Editor NEWA small library to download files with android DownloadManager from nativescript
A small library to download files with android DownloadManager from nativescript
Hi,
thank you for your plugin.
My question is: How to remove file after download.
I tried to return id of last downloaded file in:
//downloadmanager.android.js
if (this.downloads.has(id)) {
var uri = c.getString(c.getColumnIndex(android.app.DownloadManager.COLUMN_LOCAL_URI));
var cb = this.downloads.get(id);
cb(success, uri, id);
}
and then in my callback:
dm.downloadFile("https://bohosluzby.cirkev.cz/uploads/church_service.db", function(result,uri, id) {
console.log(id);
dm.manager.remove(id)
}
but app crashes with error:
An uncaught Exception occurred on "main" thread.
java.lang.RuntimeException: Error receiving broadcast Intent { act=android.intent.action.DOWNLOAD_COMPLETE flg=0x10 pkg=org.nativescript.bohosluzbyapp (has extras) } in com.tns.gen.android.content.BroadcastReceiver_frnal_ts_helpers_l58_c38__BroadcastReceiver@41f5b9e8
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:808)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5292)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
at dalvik.system.NativeStart.main(Native Method)
Caused by: com.tns.NativeScriptException:
Calling js method onReceive failed
Error: Cannot convert number to [J at index 0
File: "file:///data/data/org.nativescript.bohosluzbyapp/files/app/services/churchservicedb.service.js, line: 141, column: 33
StackTrace:
Frame: function:'', file:'file:///data/data/org.nativescript.bohosluzbyapp/files/app/services/churchservicedb.service.js', line: 141, column: 34
Frame: function:'DownloadManager.handleDownloadEvent', file:'file:///data/data/org.nativescript.bohosluzbyapp/files/app/tns_modules/nativescript-downloadmanager/downloadmanager.js', line: 46, column: 21
Frame: function:'BroadcastReceiver.onReceive', file:'file:///data/data/org.nativescript.bohosluzbyapp/files/app/tns_modules/tns-core-modules/application/application.js', line: 217, column: 22
at com.tns.Runtime.callJSMethodNative(Native Method)
at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1197)
at com.tns.Runtime.callJSMethodImpl(Runtime.java:1061)
at com.tns.Runtime.callJSMethod(Runtime.java:1047)
at com.tns.Runtime.callJSMethod(Runtime.java:1028)
at com.tns.Runtime.callJSMethod(Runtime.java:1018)
at com.tns.gen.android.content.BroadcastReceiver_frnal_ts_helpers_l58_c38__BroadcastReceiver.onReceive(android.content.BroadcastReceiver.java)
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:798)
... 9 more
Do you have a solution for deleting downloaded files after download is completed?
Thanks
My app is not on typescript, just plain javascript. Do I do it right? I can not download.
I try to download the url that is being sent to this function. But dm.downloadFile
does not work. Console log "inside downfile" is not getting called.
var DownloadManager = require('nativescript-downloadmanager');
`
function DownloadFile(url) {
let dm = new DownloadManager();
dm.downloadFile(url, function(result,uri) {
// result is a boolean, if the download was successful, it will return true
console.log("********************************* inside downfile ****************");
console.log(result);
// Uri in file:// format of the downloaded file.
console.log(uri);
// unregisterBroadcast is used to unregister the broadcast (For example if you just want to
// download a single file).
dm.unregisterBroadcast();
})
}`
Hey, I see there is a difference between the github version which has
downloadFile(url: string, options:DownloadOptions, cb: Function);
with lots of options in options. and the npm version has
downloadFile(url: string, cb: Function, directory?: string, filename?: string, title?: string, description?: string): void;
I installed it using:
tns plugin add nativescript-downloadmanager
Can't import both functions from the lib according to IDE, what should I do? Is this an error with the demo app or with the actual lib?
Hi,
do you know how I could open downloaded file on android, I successfully download new apk version of the app and I would like to open it once its done, I tried doing custom intents, but I couldn't get it working.
thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.