When I display a WebView
page in my android device (4.0), I notice that special character such as é è à are not displayed properly, like this
and this the code of my WebView
.
public class Browser extends Activity{
WebView ourBrow;
String adress;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.browser);
try{
getActionBar().setDisplayShowHomeEnabled(false);
}
catch (Exception e)
{ }
try{
ourBrow = (WebView)findViewById(R.id.wvBrowser);
ourBrow.getSettings().setJavaScriptEnabled(true);
ourBrow.getSettings().setLoadWithOverviewMode(true);
ourBrow.getSettings().setUseWideViewPort(true);
ourBrow.setWebViewClient(new ourViewClient());
ourBrow.setWebChromeClient(new WebChromeClient());
ourBrow.getSettings().setSupportMultipleWindows(true);
String url = null;
Intent intent = getIntent();
try{
if(intent != null) {
if(intent.getExtras() != null) {
url = intent.getExtras().getString("url");
}
}
if(url != null && !url.equals("")) {
ourBrow.loadUrl(url);
}
}catch (Exception e){
}
}catch(Exception e)
{
}
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
if(ourBrow != null) {
ourBrow.stopLoading();
ourBrow.onPause(); //pauses background threads, stops playing sound
ourBrow.pauseTimers(); //pauses the WebViewCore
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_goback, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch (item.getItemId()) {
// action when setting was selected
case R.id.goback:
ourBrow.stopLoading();
ourBrow.onPause(); //pauses background threads, stops playing sound
ourBrow.pauseTimers(); //pauses the WebViewCore
ourBrow.destroyDrawingCache(); //removes the view from RAM
ourBrow = null;
finish();
break;
default:
break;
}
return true;
}
public class ourViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub
//view.loadUrl(url);
view.loadDataWithBaseURL(null, url, "text/html", "utf-8", null);
return true;
}
}