I am working on a private enterprise application that involves a zoomable webview.
The problem, however, is that the webpage blocks zoom on mobile devices through the meta tags (<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
).
I have been trying and researching for a couple hours now, but I don't seem to get it bypassed.
What I've tried so far is iframing it with a custom meta, which wont work as the page has a sender protection, load custom HTML elements through the Activity itself, and tried to inject custom JavaScript code which all of those wont work in any way.
I would appreciate if someone could help me along.
My current activity:
package eu.julius.x;
import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.os.Build;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.JavascriptInterface;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
private WebView view;
boolean doubleBackToExitPressedOnce = false;
String url = "http://www.x.is/";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.view = (WebView) findViewById(R.id.webview);
view = (WebView) this.view.findViewById(R.id.webview);
view.setWebViewClient(new WebViewClient());
if (savedInstanceState == null) {
view.loadUrl(url);
}
this.view.getSettings().getBuiltInZoomControls();
this.view.getSettings().getDisplayZoomControls();
this.view.getSettings().setUseWideViewPort(true);
this.view.getSettings().setLoadWithOverviewMode(true);
this.view.getSettings().setSupportZoom(true);
this.view.getSettings().setBuiltInZoomControls(true);
this.view.getSettings().setJavaScriptEnabled(true);
WebViewClient mWebViewClient = new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
view.loadUrl("javascript:window.android.onUrlChange(window.location.href);"); }
};
view.setWebViewClient(mWebViewClient);
}
@JavascriptInterface
public void onUrlChange(String url) {
if (Build.VERSION.SDK_INT >= 19) {
view.evaluateJavascript("var metaList = javascript:document.getElementsByTagName('META');javascript:metaList[0].setAttribute('content','width=device-width, initial-scale=1.0);document.location.reload(forceGet);", new ValueCallback<String>() { public void onReceiveValue(String s) {
}
});
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
recreate();
}
});
}
}
@Override
public void onResume() {
super.onResume();
view.onResume();
}
@Override
protected void onSaveInstanceState(Bundle outState )
{
super.onSaveInstanceState(outState);
view.saveState(outState);
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState)
{
super.onRestoreInstanceState(savedInstanceState);
view.restoreState(savedInstanceState);
}