简体   繁体   中英

Website Title and Icon Showing in mobile browser but not shown in android webview

I Make an apps for my wordpress website. It is fine when I open it in mobile browser like chrome, firefox etc, But it does not work Properly in android webview. It did not show title, icon in android webview. What is the solution right now.......

chrome view

In Webview

Mainactivity.java Code public class MainActivity extends Activity {

private WebView webView = null;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    this.webView = (WebView) findViewById(R.id.webview);

    WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptEnabled(true);

    WebViewClientImpl webViewClient = new WebViewClientImpl(this);
    webView.setWebViewClient(webViewClient);

    webView.loadUrl("http://www.chaderhut24.com");
    //webView.loadData("<html><body>Hello, world!</body></html>", "text/html", "UTF-8");
}


@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if ((keyCode == KeyEvent.KEYCODE_BACK) && this.webView.canGoBack()) {
        this.webView.goBack();
        return true;
    }

    return super.onKeyDown(keyCode, event);
}

}

webviewclientimpl.java public class WebViewClientImpl extends WebViewClient {

private Activity activity = null;

public WebViewClientImpl(Activity activity) {
    this.activity = activity;
}

@Override
public boolean shouldOverrideUrlLoading(WebView webView, String url) {
    if(url.contains("chaderhut24.com")) return false;

    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    activity.startActivity(intent);
    return true;
}

}

AndroidManifest.xml

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:usesCleartextTraffic="true"
    android:theme="@style/AppTheme"
    tools:targetApi="m">

    <activity
        android:name="chaderhut.feni.shopping.dagonbhuiyan.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

I think this is due to the fact that an Android WebView only loads the contents between the body tag of the webpage by default. So to load the title and the favicon of the page you will have to use a custom WebView.

A good example code is answered in this question

The WebView class has some public methods like getTitle() and getFavicon() which may help you.

You can refer to the official docs

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM