Results 1 to 2 of 2
  1.    #1  
    In need a simple snippet of code, it will simply download the file at the URL.
    and perhaps notify the user that the download was completed. And if you can post a snippet instead of the link.

    , Thank you In advance Opal.


    PS: if you could find way to move files to different directorys, then that would be great if you post it.
  2. drnull's Avatar
    Posts
    570 Posts
    Global Posts
    571 Global Posts
    #2  
    If your app isn't named com.palm, I don't think you can download.

    However, I would imagine palm would open this up at some point, so, for development purposes, you can name your app com.palm and use the following:

    Code:
    function DownloadService() {
    }
    // fix the SLASH, make it a /
    DownloadService.prototype.URI = "palm:/[SLASH]com.palm.downloadmanager/";
    DownloadService.prototype.download = function(sceneController, target, callback, force) {
    	return sceneController.serviceRequest(this.URI, {
    		method: "download",
    		onSuccess: callback,
    		onFailure: callback,
    		parameters: {target: target, subscribe: true}});
    };
    DownloadService.prototype.downloadStatus = function(sceneController, ticket, callback) {
    	return sceneController.serviceRequest(this.URI, {
    		method: "downloadStatusQuery",
    		onSuccess: callback,
    		onFailure: callback,
    		parameters: {ticket: ticket, subscribe: true}});
    };
    
    DownloadService.prototype.cancelDownload = function(sceneController, ticket, callback) {
    	return sceneController.serviceRequest(this.URI, {
    		method: "cancelDownload",
    		onSuccess: callback,
    		onFailure: callback,
    		parameters: {ticket: ticket}});
    };
    
    // your code here:
    ...
    var downloadService = new DownloadService();
    downloadService.download(this.controller, SOME_URL, function(event) {
      Mojo.Log.error("download status: %j", event);
    });
    ...
    Having "subscribe: true" in the download request causes the download service to call your handler back until the download is finished with status updates. Take that out if you want to manage the status updates yourself by calling downloadStatus with a ticket (you get the ticket in the download callback)

    And I haven't seen any facility for moving files. All downloads go to /media/internal/downloads (but they should still be seen by the builtin apps - music player, photo viewer, pdf viewer, etc)
    Last edited by drnull; 07/23/2009 at 09:34 AM.

Posting Permissions