Showing posts with label phonegap. Show all posts
Showing posts with label phonegap. Show all posts

Saturday, May 19, 2012

Code for displaying image in Phonegap mobile application from server

Code for displaying image in Phonegap mobile application from server

I had a requirement to display the image in phonegap mobile application from Web server using JSON.
I could not find any solution over the net. My solution is below.

1) Add an images folder under Webcontent folder and add a jpeg image in it.
(Added the image picture5.jpg in the folder)
      2) Mention the Exact location of the image in the JSON String just like string or int value in the server   side code.
        EX: productMap.put("LOCAT", "http://192.178.3.2:9080/SalesManager/images/picture5.jpg");

      3) Create a new Javascript file picShow.js to get the image from the server using JSON.
            function getPicture()
            {
            $
            .getJSON("http://192.178.3.2:9080/SalesManager/getImage.action",
            {}, function(data) {
            processPictureData(data);
            });
            }
            function processPictureData(data)
            {
            $.each(data.PICTURE, function(i, product) {
            $('#productPic').attr('src', product.LOCAT);
            });
            }

            4) Create a new html to display the picture.
            <!DOCTYPE HTML>
            <html>
            <head>
            <title>Picture POC</title>
            <meta name="viewport" content="width=device-width,initial-scale=1" />
            <script src="scripts/phonegap-1.0.0rc2.js"></script>
            <script src="scripts/jquery-1.6.4.min.js"></script>
            <script src="scripts/jquery.mobile.min.js"></script>
            <script src="scripts/database.js"></script>
            <script src="scripts/synchronizeData.js"></script>
            <link rel="stylesheet" href="css/jquery.mobile.min.css" />
            <link rel="stylesheet" href="css/styles.css" />
            <script src="scripts/picShow.js"></script>
            </head>
            <body>
            <h1>Picture Demo</h1>
            <button onclick="getPicture()">click here</button>
            <div data-role="">
            <img id="productPic">
            </div>
            </body>
            </html>















Sunday, March 18, 2012

Problems with a href tag and window.location in phonegap application

I was using <a href> tag and window.location for links in the pages.But it was displaying the old page itself. 
PhoneGap gets notified whenever a new page is to be loaded.  However, there is a problem in Phonegap (phonegap-1.0.0rc2 and older versions) in using a <a href> tag or window.location.
As a result, PhoneGap doesn't have any way to intercept the request.So it continues to display old page or it will not be able to handle the parameters passed from previous page.
Code with problems:
<a href="HomePage.html">Home</a>
and
window.location="HomePage.html";
Solution: 
1) Use navigator.app.loadUrl(file:///android_asset/HomePage.html); instead of 
window.location or <a href tag.
2) Try to make use of same page with sections (<div> tag) than having code written
over multiple page.

Monday, January 9, 2012

"Project has no default.properties file! Edit the project properties to set one."error on adding existing phonegap project into workspace

I was facing the this issue  when i tried to add an existing Phonegap project into another workspace.
Reason:
Android Tools automatically generate the file default.properties which tells about target API level.
But when the project is added into the another workspace this file does not gets created.
Resolution:
Create a properties file default.properties directly under the Phonegap project directory.
Mention the target API level in it.
(ex: If the target API that you want to use is 8,then add the following code in the default.properties file)
 target=android-8

Tuesday, January 3, 2012

How to resolve Conversion to Dalvik format failed with error 1 in Phonegap project?



Project shows this error because the phonegap jar (phonegap-1.0.0rc2.jar) /any other jar  file is not stored in the proper folder in the project setup.
I have created a Lib folder under src folder and placed the phonegap  jar into it and added the jar to buildpath which resulted in the error.


Resolution:
1) Remove the Phonegap jar/any other jar from the build path.
In the eclipse select project -> Properties ->Java Build Path.Select the tab libraries.Then select the phonegap jar and remove it.
2) Add the lib folder directly under the project(i.e not under any folders in project) and
 place the phonegap jar under it. Add the phonegap jar  to build path.
Then Clean and build the project.



Sample Exception stracktrace
[2012-01-03 18:57:54 - MedicalSalesManApplication] Dx
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Lcom/phonegap/AccelListener;
[2012-01-03 18:57:54 - MedicalSalesManApplication] Dx at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:123)
[2012-01-03 18:57:54 - MedicalSalesManApplication] Dx at com.android.dx.dex.file.DexFile.add(DexFile.java:163)
[2012-01-03 18:57:54 - MedicalSalesManApplication] Dx at com.android.dx.command.dexer.Main.processClass(Main.java:486)
[2012-01-03 18:57:54 - MedicalSalesManApplication] Dx at com.android.dx.command.dexer.Main.processFileBytes(Main.java:455)
[2012-01-03 18:57:54 - MedicalSalesManApplication] Dx at com.android.dx.command.dexer.Main.access$400(Main.java:67)
[2012-01-03 18:57:54 - MedicalSalesManApplication] Dx at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:394)
[2012-01-03 18:57:54 - MedicalSalesManApplication] Dx at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:245)
[2012-01-03 18:57:54 - MedicalSalesManApplication] Dx at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:131)
[2012-01-03 18:57:54 - MedicalSalesManApplication] Dx at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:109)
[2012-01-03 18:57:54 - MedicalSalesManApplication] Dx at com.android.dx.command.dexer.Main.processOne(Main.java:418)
[2012-01-03 18:57:54 - MedicalSalesManApplication] Dx at com.android.dx.command.dexer.Main.processAllFiles(Main.java:329)
[2012-01-03 18:57:54 - MedicalSalesManApplication] Dx at com.android.dx.command.dexer.Main.run(Main.java:206)
[2012-01-03 18:57:54 - MedicalSalesManApplication] Dx at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[2012-01-03 18:57:54 - MedicalSalesManApplication] Dx at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
[2012-01-03 18:57:54 - MedicalSalesManApplication] Dx at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
[2012-01-03 18:57:54 - MedicalSalesManApplication] Dx at java.lang.reflect.Method.invoke(Unknown Source)
[2012-01-03 18:57:54 - MedicalSalesManApplication] Dx at com.android.ide.eclipse.adt.internal.build.DexWrapper.run(DexWrapper.java:179)
[2012-01-03 18:57:54 - MedicalSalesManApplication] Dx at com.android.ide.eclipse.adt.internal.build.BuildHelper.executeDx(BuildHelper.java:585)
[2012-01-03 18:57:54 - MedicalSalesManApplication] Dx at com.android.ide.eclipse.adt.internal.build.builders.PostCompilerBuilder.build(PostCompilerBuilder.java:490)
[2012-01-03 18:57:54 - MedicalSalesManApplication] Dx at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:728)
[2012-01-03 18:57:54 - MedicalSalesManApplication] Dx at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
[2012-01-03 18:57:54 - MedicalSalesManApplication] Dx at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:199)
[2012-01-03 18:57:54 - MedicalSalesManApplication] Dx at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:239)
[2012-01-03 18:57:54 - MedicalSalesManApplication] Dx at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:292)
[2012-01-03 18:57:54 - MedicalSalesManApplication] Dx at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
[2012-01-03 18:57:54 - MedicalSalesManApplication] Dx at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:295)
[2012-01-03 18:57:54 - MedicalSalesManApplication] Dx at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:351)
[2012-01-03 18:57:54 - MedicalSalesManApplication] Dx at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:374)
[2012-01-03 18:57:54 - MedicalSalesManApplication] Dx at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:143)
[2012-01-03 18:57:54 - MedicalSalesManApplication] Dx at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:241)
[2012-01-03 18:57:54 - MedicalSalesManApplication] Dx at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
[2012-01-03 18:57:54 - MedicalSalesManApplication] Dx 1 error; aborting
[2012-01-03 18:57:54 - MedicalSalesManApplication] Conversion to Dalvik format failed with error 1
[2012-01-03 18:58:45 - MedicalSalesManApplication] Dx

Resolve "Target runtime Apache Tomcat v6.0 is not defined." error

Go to window ->preferences ->Server->Runtime environments . add server Apache Tomcat v6.0 Mention the directory where apache-toma...