i am getting HTML data from server using json webservice and display in webview in iphone is display perfectly with screen size but in android is not display prefect here i put down the webservice link and code and screen shot of android and iphone.
HomeActivity.java
public class HomeActivity extends Activity
{
WebView webview;
ImageView imagemenu;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
imagemenu=(ImageView)findViewById(R.id.imagemenu);
copyFile(HomeActivity.this,"verdana.ttf");
new HomeAsynctask().execute("");
webview = (WebView) findViewById(R.id.homewebview);
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setLoadWithOverviewMode(true);
webview.getSettings().setUseWideViewPort(true);
webview.getSettings().setBuiltInZoomControls(true);
webview.getSettings().setSupportZoom(true);
imagemenu.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
Intent i = new Intent(HomeActivity.this,HomeListActivity.class);
i.setFlags(i.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(i);
}
});
}
// Asynctask for getting the home data from url
public class HomeAsynctask extends AsyncTask<String, String,String>
{
String detail;
@Override
protected void onPreExecute()
{
// loader
}
@Override
protected String doInBackground(String... params)
{
try
{
JsonParser jparser = new JsonParser();
String url="http://www.bridge.co.at/webservices/services.php?method=content&uid=127";
String homedata=jparser.getdata(url);
Log.e("Home Data","----->"+homedata);
JSONObject jobject = new JSONObject(homedata);
JSONArray jarray =jobject.getJSONArray(ClassVariable.HOME.CONTENT);
detail=jarray.getJSONObject(0).get(ClassVariable.HOME.DETAIL).toString();
Log.e("Detail","----->"+detail);
}
catch (Exception e)
{
e.printStackTrace();
}
return detail;
}
@Override
protected void onPostExecute(String result)
{
String htmlData=getHtmlData(HomeActivity.this,result);
webview.loadDataWithBaseURL(null,htmlData,"text/html","utf-8","about:blank");
}
}
private boolean copyFile(Context context,String fileName)
{
boolean status = false;
try
{
FileOutputStream out = context.openFileOutput(fileName, Context.MODE_PRIVATE);
InputStream in = context.getAssets().open(fileName);
// Transfer bytes from the input file to the output file
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
// Close the streams
out.close();
in.close();
status = true;
}
catch (Exception e)
{
System.out.println("Exception in copyFile:: "+e.getMessage());
status = false;
}
System.out.println("copyFile Status:: "+status);
return status;
}
private String getHtmlData(Context context, String data)
{
String head = "<head><style>@font-face {font-family: 'verdana';src: url('file:///android_asset/fonts/verdana.ttf');}body {width=600;height=1024;margin:10px;font-family:'verdana';font-size:12px}</style></head>";
String htmlData= "<html>"+head+"<body>"+data+"</body></html>" ;
return htmlData;
}
}