2

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>");

2 Answers 2

1

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
0

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

1
  • I'm not trying to make a website look like iPhone, I'm trying to get websites to see me as an iPhone App Mode browser. Feb 17, 2011 at 17:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.