getJSON returning null phonegap(android) - android

i am developing phone-gap app in android. In app I am calling a servlet returning JSON. Under app code I am calling following method through javascript in index.html
JQuery.getJSON(servleturl,function(data){alert(data)});
When running in emulator the alert is getting displayed, but data is always null. However if i launch the index.html (main application file in phonegap) from browser, I am able to get Json.
same thing happens even if I use $ajax.
please help me and let me know what I am doing wrong.

A little bit later, but I had the same problem today, and I've solved it, so if you didn't sort this problem this would help.
So, the problem is not in JSON or in the phonegap, but it's in the AndroidManifest.xml file.
You should have a tag like this:
<uses-permission android:name="android.permission.INTERNET" />
this should allow your application to work with Internet. Without this connection to Internet from your application is forbidden. That tag need to be placed right after the start tag.
Check Phonegap sample manifest for full list of possible permissions.
hope this will help to someone.

I fixed up (read made the changes to get working under a newer version of node.js) a little tool called ibug that John Boxall wrote that I found useful for debugging on the phone (since there is no real way to do it except debug.log and looking at XCodes console window. Its basically a stripped down firebug lite, and its hosted on github as ibug. Hopefully it will help you figure out why things aren't working.

Related

Weinre do not show target for Cordova Android App running on handphone

I really need some help here...
I have developed a simple app using cordova and I wish to debug the app using weinre for further improvement.
The problem is when i host weinre client and access with browser to http://192.168.0.111:8080/client/#anonymous
the app does not show as a target in the client..
I have insert this script import line at the last part of my index.html
<script src="http://192.168.0.111:8080/target/target-script-min.js#anonymous"></script>
In config.xml, i put <access origin="*" />
and in AndroidManifest.xml, i put <uses-permission android:name="android.permission.INTERNET" />
I have also try to open my index.html with the browser of computer which hosting weinre and it's been indicate as a target. Which mean the code should be working fine.
I have also try to access http://192.168.0.111:8080 and the weinre info page is showing up. which mean the ip is correct and accessible from my handphone.
but I wonder why when i run the app, weinre dint show my app as a target. Do I miss out some important step to allow my app to be accessible?
Please help.
After all I still cannot identified the issue, it might be configuration issue and it might not... any suggestion or answer will be welcome.
and to provide solution for those who have similar situation as me, you can try this https://developer.chrome.com/devtools/docs/remote-debugging.
It's working fine for my case. Besides, it's much easier to setup and more familiar interface. You can even step through your js line by line just like what you can do with your pages.
for the moments, this is the best solution i can get.

Android failing to connect to my servlet

I am having trouble getting my android app connected to just some particular servlets running on my server. I am getting an UnknownHostException when trying to connect. I assure you I have used the
<uses-permission android:name="android.permission.INTERNET" />
in my Manifest file and have already gone through atleast 5 or 6 similar SO questions.
When I use the URL which is shown with the original exception, in a browser, the servlet page shows up just fine. (Even in the device's browser!)
Note:
I am running this on a physical device
This happens only when I try and connect to some servlets. Not all. (Talk about weird!)
I'll give the codes if you want it.
At last, this was a silly problem.
What I did was, I used just http:/ instead of http:// in front of the URL and when I pasted this in the browser, the browser auto-corrected it into http://. Changing that back to http:// fixed it!
I leaving this here hoping that this might reduce the hours of headache caused by this annoying problem and help someone.

Weinre does not find any target

Sorry for the newbie question, but I spent the whole day trying to figure out why the target list remains empty.
This is what I've done so far:
Launched the Weinre host, bounded to my desktop ip adress
(192.168.0.38)
Checked it on Chrome : the host is bounded to
192.68.0.38:8080
Checked that the device is able to access to 192.168.0.38:8080/target/target-script-min.js#anonymous
White-listed both 192.168.0.38:8080 and 192.168.0.38 in config.xml
Added the script call in the index.html
Still the target list remains empty when I launch the app on the device from ADT...
What should I do next?
Thanks!
___ EDIT
I tried the demo, and it's working!
So what makes the difference between calling the script from a demo file, or from the application?
Turns out for me, the problem was that the mobile device silently switched over to another Wi-Fi network (than the one my computer was on), thus rendering the Weinre JS Script unreachable from within the app.
It's different than the issue described above (since, for Yako, the example scripts were working fine), but thought it could help somebody someday.
My issue was that I kept trying to access a page anchor. Apparently that doesn't work too well so I have to load the page first with no anchor, then add the anchor separately.
Finally, it's working!
It seems I only had to wait a little bit after app initalization!??
For all of you who still have to use weinre and have the same problem, I just want to share my mistake:
I did not whitelist my IP-address in the config.xml
maybe some of you have the same mistake.

Why can't I load my local page using Webview

I came to seek help, I have search, read and tried several solutions I came across, but none seem to work for me,
I can't access my local website from the android emulator, using "http://10.0.2.2", but I tried it on other computer, and it works, I'm using Android Webview, does it have something to do with htaccess? How can I determine which htaccess is settings is in effect?
Is there anything I've missed to make it work, btw, when I try to access the local page using the builtin browser, I can access it without any troubles.
Do you have the android.permission.INTERNET permission in your manifest? For more information see: http://developer.android.com/reference/android/Manifest.permission.html

Not able to run hello world prog in phonegap

I m new to phonegap.So i was trying to run Hello world html file in android emulator which comes with phonegap.But i m getting this error
Application Error
There was a network error.(file:///android_asset/www/index.html)
I checked HTML file by clicking run with browser in eclipse and its running good.But when it comes to run as Android application then it is giving error.
Before posting this question i Googled for solutions and there i got to know that we should enable permission for internet,but it is also done and also LAN is disabled as some one stated in this website as solution.And also i got to know that its problem with Android SDK and every phonegap user facing this problem.Is that true??
I m really good at HTML,CSS and Javascript.So i opt phonegap.But now i m very sad.
Last question.Will it give same problem if i use XCode for iPhone in Phonegap??
Regards
Devaraju
Try adding this permission too.
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
This network error shows up for various reasons, but my guess is that your config.xml is looking for index.html and you have named your html page something else.

Categories

Resources