Browser --- Change bookmark, homepage and FAQ

Browser development tasks usually include: changing bookmark (bookmark) and homepage (preset homepage)

bookmark

List the bookmark list in .xml, and put the replacement URLs here.

    <add-resource type="array" name="bookmark_url"></add-resource>
    <string-array name="bookmark_url">
        <item>Google</item>
        <item>http://www.google.com/</item>
    </string-array>

In the .java logic, the value of resId_DefaultUrl is the same as the name value in add-resource and string-array.

            //获取.xml中的资源
            Resources res = getContext().getResources();
            //获取机种ID
            String carrierId = com.android.browser.Browser.getCarrier();
            //通过拼接的方式拼接机种ID来识别bookmark的网址URL
            int resId_DefaultUrl = res.getIdentifier("bookmark_url_" + carrierId, "array", getContext().getPackageName());

homepage (preset homepage)

List the home page URL in .xml

    <add-resource type="string" name="homepage_url"></add-resource>
    <string name="homepage_url"   translatable="false">https://www.google.com/</string>

In .java logic, the idea is the same as bookmark

//获取机种ID
String carrierId = com.android.browser.Browser.getCarrier();
//通过拼接的方式拼接机种ID来识别homepage的网址URL
int resId_DefaultUrl = mContext.getResources().getIdentifier("homepage_url_" + carrierId, "string", mContext.getPackageName());

Problems you may encounter during development

1. Android P changes the default browser homepage

Where CID is the mobile phone ID, source = android-home is the current environment is the Android environment

    <!-- The default homepage. -->
    <string name="homepage_base" translatable="false">
        https://www.google.com/webhp?client={CID}&amp;source=android-home</string>

Android 10 and later

    <!-- The default homepage. -->
    <string name="homepage_base" translatable="false">
        https://www.baidu.com/</string>

2. The URL you are using is https://www.google.com/

But you will find that the URL of the actual accessed website is https://www.google.com.hk/

This is because Google's servers have moved away from mainland China. When users in mainland China use Google services, they will automatically jump to https://www.google.com.hk/ in Hong Kong. There is keyword filtering and it is occasionally unstable.

Solution: Use https://www.google.com/ncr

ncr is no country redirection, a command that forces no jump

3. Try to write the URL as standard as https://www.google.com/

What I wrote before was https://www.google.com. Because the / was missing and the URL was not standardized, some mobile phone hardware could not recognize the URL.

Guess you like

Origin blog.csdn.net/m0_50408097/article/details/122433824