• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Android Web View Problems

Kerry2008

Lurker
Oct 23, 2013
1
0
Hi, I am a newish android developer and am having problems rendering a responsive web site on the native webview in an Android app I am working on. It loads the site fine etc but always loads them in the desktop version. It is the same for all responsive sites.

The following is the code in my Java file and it doesn't matter what I do I always get the desktop version. The responsive site works fine if I load it on my mobile phone, or even on the IOS app I have delverloped. However, using the webview embedded in my app it just loads the desktop version.

[HIGH]package com.flairfront.cacsssincomingstudents;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebView;

public class Programme_Web extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
String url = getIntent().getStringExtra("seriesId");

//Remove notification bar
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

setContentView(R.layout.activity_programme__web);
WebView mainWebView = (WebView) findViewById(R.id.programme_webView);
mainWebView.getSettings().setUserAgentString("Mozilla/5.0 (Linux; U; Android 2.2.1; en-us; Nexus One Build/FRG83) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1");
mainWebView.setInitialScale(50);
mainWebView.loadUrl(url);

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.programme__web, menu);
return true;
}
[/HIGH]
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones