Topic
  • 12 replies
  • Latest Post - ‏2012-03-14T06:18:12Z by SystemAdmin
SystemAdmin
SystemAdmin
570 Posts

Pinned topic [Solved] Porting PhoneGap to Worklight

‏2012-03-06T12:18:55Z |
Hi all,

I'm facing a weird issue with porting a phonegap app ( on android ) to WorkLight.

I'm trying out a PhoneGap photo upload example found here ( https://www.ibm.com/developerworks/mydeveloperworks/blogs/94e7fded-7162-445e-8ceb-97a2140866a9/entry/upload_a_picture_using_phonegap_on_android8 )
, and it works perfectly on PhoneGap ( Android ).

However, when i tried to port it over to Worklight, I am receiving a cross domain error.

The steps which I have done to port the PhoneGap app ( Android ) to Worklight are:

Create a hello world project by following :
1) Module 2.2
2) Module 3
3) Module 3.3

based on the slides here : http://www.worklight.com/download/get-started/4.2.1/

I have gotten the 'hello world' example working.

Next, i copied and paste the JavaScript and HTML code to the main html ( HelloWorld.html ).

I than deployed the WorkLight app and than ran the app on Android Emulator ( targetted environment 2.1 ), and tried to upload or read photos.

But i received an error code 3 ( for uploading photos ) and errors for retrieving photos.

I've tried checking the app on the WorkLight console and saw that I am receiving cross domain errors even though the Android permissions are correct ( internet allowed ).

May I know how do I fix this problem ?

If i remember correctly, PhoneGap apps should not have any cross domain issues, but why
do i have the above mentioned problems when i port it over to Worklight ?

Please advise~~

Thanks!
  • SystemAdmin
    SystemAdmin
    570 Posts

    Re: [Solved] Porting PhoneGap to Worklight

    ‏2012-03-06T12:40:58Z  
    Hi eugene.

    Can you please zip and attach your Worklight project?
  • SystemAdmin
    SystemAdmin
    570 Posts

    Re: [Solved] Porting PhoneGap to Worklight

    ‏2012-03-07T02:19:37Z  
    Hello,
    is there an email i can send to ?

    Best Regards,
    Eugene
  • SystemAdmin
    SystemAdmin
    570 Posts

    Re: [Solved] Porting PhoneGap to Worklight

    ‏2012-03-07T04:17:14Z  
    Hi,
    attached is the project folder.

    I've created the Worklight Environment -> Android
    already so there's a Android folder in it.

    Best.
  • SystemAdmin
    SystemAdmin
    570 Posts

    Re: [Solved] Porting PhoneGap to Worklight

    ‏2012-03-07T10:36:11Z  
    Hi Eugene.

    I had a problem with line 116 in the Upload.html (params.contract_id = document.getElementById('contract_id').value;).
    There is no element with that ID in the HTML file and "contract_id" is not used elsewhere in the application, so I just commented it out.

    I've tried the application you've sent and it is working out of the box (after the change written above) on an emulator (2.1) and an Android device, without seeing any issues.

    There is no camera on an emulator, so I've saved a picture to the SD card and I've uploaded it.
    On the device everything worked fine.

    Viewing the application as preview will not work for a few reasons.
    1) There will be a cross domain issue (when the application works from an Android device/emulator the application does not belong to a domain (it runs as a .), so accessing the upload server will not pose any issues.
    2) In preview the application has no access to PhoneGap, therefor there will be errors in the JavaScript calling the PhoneGap API.

    If you still have this problem, can you send us a WireShark or similar log? I need some more information.
  • SystemAdmin
    SystemAdmin
    570 Posts

    Re: [Solved] Porting PhoneGap to Worklight

    ‏2012-03-07T11:25:38Z  
    Hi,
    thanks for the reply!

    By "preview" are u referring to trying the app in the Android Emulator ?

    If so, is there any way ( or workarounds) i can test the app ( using PhoneGap API ) using the Android Emulator ?

    Thanks!
  • SystemAdmin
    SystemAdmin
    570 Posts

    Re: [Solved] Porting PhoneGap to Worklight

    ‏2012-03-07T12:30:34Z  
    Hi Eugene.

    By preview I mean from the Worklight console (http://localhost:8080/console/index.html#catalog) clicking on the preview as dropdown and choosing Android.

    When you've created an Android emulator did you assign the SD Card any space? You can not use the emulator camera without space for the SD card.
  • SystemAdmin
    SystemAdmin
    570 Posts

    Re: [Solved] Porting PhoneGap to Worklight

    ‏2012-03-07T13:55:24Z  
    Hello,
    yes I did assign the SD card.

    And I manage to take photos with the project i've sent u.

    I can also select photo from my sdcard.

    But i can't upload or read photo from server.

    Any suggestions ?
  • SystemAdmin
    SystemAdmin
    570 Posts

    Re: [Solved] Porting PhoneGap to Worklight

    ‏2012-03-07T14:09:33Z  
    Hi Eugene.

    In the emulator, can you access the upload server (http://www.liangeugene.com/portfolio_stuff/mobile/upload.php) via the browser?
  • SystemAdmin
    SystemAdmin
    570 Posts

    Re: [Solved] Porting PhoneGap to Worklight

    ‏2012-03-07T14:27:19Z  
    Hi,
    yes i can access the webpage in the emulator via the browser.
    Best.
  • SystemAdmin
    SystemAdmin
    570 Posts

    Re: [Solved] Porting PhoneGap to Worklight

    ‏2012-03-08T15:17:20Z  
    So, any advice on fixing my weird error ?

    Thanks!
  • IdanAdar
    IdanAdar
    288 Posts

    Re: [Solved] Porting PhoneGap to Worklight

    ‏2012-03-11T14:46:53Z  
    Hi eugene.

    Could you please provide us with the full description of the error you are receiving during upload (the error code 3 you have mentioned)?
    Does it perhaps also pinpoint to a line in the code? A way to do this would be to add alert()s in various stages in the code to locate it.
  • SystemAdmin
    SystemAdmin
    570 Posts

    Re: [Solved] Porting PhoneGap to Worklight

    ‏2012-03-14T06:18:12Z  
    Hello,
    I somehow managed to fix it!

    Thanks !

    Thank you for your help!

    Best.