I made a simple android application in phone gap,jQuery mobile, HTML5 with a simple getJSON data encoding . The application working well in Browser . But not in android .
When googled I found that android cant connect to internet . So that I added the following
<uses-permission android:name="android.permission.INTERNET" />
But Still my application doesn't getting jSON data .. In browser its working well
my js file looks like
function getMovies(){
var serviceURL = "http://myserver.com/";
alert("TEST"); // THIS WILL WORK ON BROWSER AND APPLICATION
$.getJSON(serviceURL + 'movies.php?jsoncallback=?',null, function(data) {
alert(data.result); // THIS WILLL WORK ON BROWSER
var movies=data.result;
$.each(movies, function(index, movie) {
$('#movielist ul').append(
'<li><div class="image"></div><div class="content">'+
'<div class="moviename">'+movie.movie+'</div>'+
'<div class="moviedetails">Description</div>'+
'</div></li>'
);
});
});
}
my PHP code in server looks like
$sql=mysql_query("SELECT * FROM filims");
$result=array();
$i=0;
while($row=mysql_fetch_array($sql)){
$result[$i]['id']=$row['id'];
$result[$i]['movie']=$row['movie'];
//$result[$i]['image']=$row['image'];
$i++;
}
$output=array();
$output['result']=$result;
$output['error']=0;
echo $_GET['jsoncallback'].'('.json_encode($output).')';
my AndroidManifest.xml looks like
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.phonegap.helloworld"
android:versionCode="1"
android:versionName="1.0" >
<supports-screens
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:resizeable="true"
android:anyDensity="true"
/>
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
<uses-sdk android:minSdkVersion="7" />
<uses-feature />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".App"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.phonegap.DroidGap" android:label="@string/app_name" android:configChanges="orientation|keyboardHidden"> <intent-filter> </intent-filter> </activity>
</application>
</manifest>
Plese help me, Thanks in advance
Try adding
myserver.com
or*
to theExternalHosts
option in thePhoneGap.plist