开发者

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;
        }
    });
开发者_JAVA百科
    webView.loadUrl("<website>");


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜