Grantland Chew
Grantland Chew

Reputation: 2630

Is it possible to mask an Android WebView as an iPhone "App Mode" safari browser?

So I know some websites check to see if it's being hit by an iPhone App Mode browser by checking window.navigator.standalone. Is it possible to mask an Android webview as an iPhone App Mode browser?

I've tried the following code, but it doesn't seem to do the trick against the site I'm trying to get to work.

WebView webView = new WebView(this);
    webView.getSettings().setJavaScriptEnabled(true);
    /* WebViewClient must be set BEFORE calling loadUrl! */
    webView.setWebViewClient(new WebViewClient() {
        @Override public void onPageStarted(WebView view, String url, Bitmap favicon) {

        }
        // intercept page finished event
        @Override public void onPageFinished(WebView view, String url) {
            if(DEBUG) Log.v(TAG, "done");
            view.loadUrl("javascript:javascript:(function() { " +
                    "window.navigator.standalone=1;" +
                    "})()");
        }
        // intercept clicked link event--load in this webview
        @Override public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);

            return true;
        }
    });

    webView.loadUrl("<website>");

Upvotes: 2

Views: 1049

Answers (2)

Rohit Mandiwal
Rohit Mandiwal

Reputation: 10462

Try to draw a layout using the iPhone stencil images and use that layout with your webview activity by setContentView(LAYOUT_ID)

Upvotes: 0

chilitechno.com
chilitechno.com

Reputation: 1575

WebSettings.setUserAgentString() is probably what you want.

Set it to something like:

Mozilla/5.0 (iPhone; U; CPU OS 4_3_2 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Mobile

Upvotes: 1

Related Questions