0 Replies Latest reply on Sep 11, 2011 2:19 PM by matthiaswille

    File.openWithDefaultApplication throws error #0 on Android devices

    matthiaswille

      I'm using File.openWithDefaultApplication to launch a file after it has been downloaded (via a web service) from a Domino server with its default application. The AIR application in which I'm doing this is running on Android devices (test device is a HTC Desire HD) as well as on the Blackberry Playbook (iOS is not testet yet with regards to the file download functionality).

       

      Whilst File.openWithDefaultApplication is working fine on the Playbook (images, Word and text documents, Excel spreadsheets and pdf files are opened correctly), the same code throws an error code #0 on Android devices.

       

      The following code snipset is the result function of the web service call

       

              private function dbdownloadfile_result(event:ResultEvent):void
              {
                  try
                  {               
                      if (event.result is ByteArray)
                      {
                          this.localfile  = File.documentsDirectory;

                          this.localfile  = this.localfile.resolvePath("download/"+ this.lst_filename);
                          this.filebytes  = event.result as ByteArray;
                          this.filestream = new FileStream();
                         
                          this.filestream.open(this.localfile, FileMode.WRITE);
                          this.filestream.writeBytes(this.filebytes, 0, this.filebytes.bytesAvailable);                   
                          this.filestream.close();
                         
                          if (this.customlistener != null)
                          {
                              this.customlistener(event);
                          }
                      }
                      else
                      {
                          super.wsrvop_fault(event as FaultEvent);
                      }
                  }
                  catch (err:Error)
                  {
                      if (this.customerrorhandler == null)
                          trace(err.getStackTrace());
                      else
                          this.customerrorhandler(err);
                  }
                  finally
                  {
                      if (this.customfinallyhandler != null) this.customfinallyhandler(null);
                  }
                 
                  this.wsrv.showProgressBar(false);
              }

       

      The above code creates a file in a sub-directory "download" in the device's documentDirectory. The filename depends on the attachment name stored on the Domino server. The above code is calling the customlistener after the file has been created in the "download" directory...

       

      private function downloadOK(event:ResultEvent):void
      {
          try
          {
              trace(globals.DBFUTL.localfile.nativePath);
              trace(globals.DBFUTL.localfile.name);
              trace(globals.DBFUTL.localfile.url);

       

              globals.DBFUTL.localfile.addEventListener(IOErrorEvent.IO_ERROR,fileErrorIO);
              globals.DBFUTL.localfile.addEventListener(SecurityErrorEvent.SECURITY_ERROR,fileErrorSec) ;

       

              globals.DBFUTL.localfile.openWithDefaultApplication();
          }
          catch (err:Error)
          {
              trace(err.message);
              trace(err.errorID.toString());
          }
      }

       

      The above code generates following console entries...

       

      /mnt/sdcard/download/joan.JPG
      joan.JPG
      file:///mnt/sdcard/download/joan.JPG
      Error #0
      0

       

      As said above, the same code works flawlessly on the Blackberry Playbook. I also can open the file on my Android using the file browser. So everything seems to be alright. Just File.openWithDefaultApplication doesn't want to work.

       

      Any ideas what I might do wrong? Or is this bug?