必威体育Betway必威体育官网
当前位置:首页 > IT技术

Android chrome浏览器的定制

时间:2019-09-30 03:43:20来源:IT技术作者:seo实验室小编阅读:68次「手机版」
 

android浏览器

最近在做海外项目需要定制chrome浏览器的书签和主页,在8.1的项目上实现,当时手机还没有预制GMS,只能下载chrome 这个apk做实验,出现了很多问题,书签没有作用,安装了gms里面的chrome,主页又没生效,六神无主,经过网上的文档发现,GMS必须预制才能生效

1.预制书签。

预制书签很简单 ,只需要改系统自带的原生代码的目录下

.\packages\providers\PartnerBookmarksProvider

代码 这些都是自带的

src\com\Android\providers\partnerbookmark


/*
 * Copyright (C) 2012 The android open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by APPlicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.providers.partnerbookmarks;

import android.content.contentprovider;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.UriMatcher;
import android.content.res.configuration;
import android.content.res.resources;
import android.content.res.TypedArray;
import android.database.Cursor;
import android.database.DatabaseUtils;
import android.database.MatrixCursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteQuerybuilder;
import android.net.Uri;
import android.text.TextUtils;
import android.util.Log;

import java.io.ByteArrayoutputstream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
 * Default partner bookmarks provider implementation of {@link PartnerBookmarksContract} API.
 * It reads the flat list of bookmarks and the name of the root partner
 * bookmarks folder using getresources() API.
 *
 * Sample resources structure:
 *     res/
 *         values/
 *             strings.xml
 *                  string name="bookmarks_folder_name"
 *                  string-array name="bookmarks"
 *                      item title1
 *                      item URL1
 *                      item TITLE2
 *                      item URL2...
 *             bookmarks_icons.xml
 *                  array name="bookmark_preloads"
 *                      item @raw/favicon1
 *                      item @raw/touchicon1
 *                      item @raw/favicon2
 *                      item @raw/touchicon2
 *                      ...
 */
public class PartnerBookmarksProvider extends ContentProvider {
    private static final String TAG = "PartnerBookmarksProvider";

    // URI matcher
    private static final int URI_MATCH_BOOKMARKS = 1000;
    private static final int URI_MATCH_BOOKMARKS_ID = 1001;
    private static final int URI_MATCH_BOOKMARKS_FOLDER = 1002;
    private static final int URI_MATCH_BOOKMARKS_FOLDER_ID = 1003;
    private static final int URI_MATCH_BOOKMARKS_PARTNER_BOOKMARKS_FOLDER_ID = 1004;

    private static final UriMatcher URI_MATCHER = new UriMatcher(UriMatcher.NO_MATCH);
    private static final Map<String, String> BOOKMARKS_PROJECTION_MAP
            = new HashMap<String, String>();

    // Default sort order for unsync'd bookmarks
    private static final String DEFAULT_BOOKMARKS_SORT_ORDER =
            PartnerBookmarksContract.Bookmarks.ID + " DESC, "
                    + PartnerBookmarksContract.Bookmarks.ID + " ASC";

    // Initial bookmark id when for getResources() importing
    // Make sure to fix tests if you are changing this
    private static final long FIXED_ID_PARTNER_BOOKMARKS_ROOT =
            PartnerBookmarksContract.Bookmarks.BOOKMARK_parent_ROOT_ID + 1;

    // DB table name
    private static final String TABLE_BOOKMARKS = "bookmarks";

    static {
        final UriMatcher matcher = URI_MATCHER;
        final String authority = PartnerBookmarksContract.AUTHORITY;
        matcher.addURI(authority, "bookmarks", URI_MATCH_BOOKMARKS);
        matcher.addURI(authority, "bookmarks/#", URI_MATCH_BOOKMARKS_ID);
        matcher.addURI(authority, "bookmarks/folder", URI_MATCH_BOOKMARKS_FOLDER);
        matcher.addURI(authority, "bookmarks/folder/#", URI_MATCH_BOOKMARKS_FOLDER_ID);
        matcher.addURI(authority, "bookmarks/folder/id",
                URI_MATCH_BOOKMARKS_PARTNER_BOOKMARKS_FOLDER_ID);
        // Projection maps
        Map<String, String> map = BOOKMARKS_PROJECTION_MAP;
        map.put(PartnerBookmarksContract.Bookmarks.ID,
                PartnerBookmarksContract.Bookmarks.ID);
        map.put(PartnerBookmarksContract.Bookmarks.TITLE,
                PartnerBookmarksContract.Bookmarks.TITLE);
        map.put(PartnerBookmarksContract.Bookmarks.URL,
                PartnerBookmarksContract.Bookmarks.URL);
        map.put(PartnerBookmarksContract.Bookmarks.TYPE,
                PartnerBookmarksContract.Bookmarks.TYPE);
        map.put(PartnerBookmarksContract.Bookmarks.PARENT,
                PartnerBookmarksContract.Bookmarks.PARENT);
        map.put(PartnerBookmarksContract.Bookmarks.FAVICON,
                PartnerBookmarksContract.Bookmarks.FAVICON);
        map.put(PartnerBookmarksContract.Bookmarks.TOUCHICON,
                PartnerBookmarksContract.Bookmarks.TOUCHICON);
    }


...................
...................
...................
  @Override
    public String getType(Uri uri) {
        final int match = URI_MATCHER.match(uri);
        if (match == UriMatcher.NO_MATCH) return null;
        return PartnerBookmarksContract.Bookmarks.CONTENT_ITEM_TYPE;
    }

    @Override
    public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
        throw new UnsupportedOperationException();
    }
}

代码里面有注释 ,只需要修改一下 res/values的资源就可以实现书签的定制

这里写图片描述

strings.xml

<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
    <string name="bookmarks_folder_name" translatable="false">Partner Bookmarks</string>
    <string-array name="bookmarks" >
     <item>Goolgle</item>
     <item>http://www.Google.com/</item>  
    </string-array>
</resources>
bookmarks_icons.xml

<resources>
    <array name="bookmark_preloads" >
    <item>@raw/a</item>
    <item>@raw/b</item>
    </array>
</resources>

只需要配置好,书签可以配置成功

2.主页配置

从网上下载代码 放入到

这里写图片描述

同级目录下

package com.android.providers.partnerbookmarks;

import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.UriMatcher;
import android.database.Cursor;
import android.database.MatrixCursor;
import android.net.Uri;

/**
 * Created by [email protected] 2018/3/12.
 */

public class PartnerHomepageProvider extends ContentProvider {


    // 设置默认的主页网址
    private static String HOMEPAGE_URI = "http://www.baidu.com";
    private static final int URI_MATCH_HOMEPAGE = 0;
    private static final UriMatcher URI_MATCHER = new UriMatcher(UriMatcher.NO_MATCH);
    static {
        URI_MATCHER.addURI("com.android.partnerbrowsercustomizations", "homepage",
                URI_MATCH_HOMEPAGE);
    }
    @Override
    public boolean onCreate() {
        return true;
    }

    @Override
    public String getType(Uri uri) {
        switch (URI_MATCHER.match(uri)) {
            case URI_MATCH_HOMEPAGE:
                return "vnd.android.cursor.item/partnerhomepage";
            default:
                return null;
        }
    }

    @Override
    public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
                        String sortOrder) {
        switch (URI_MATCHER.match(uri)) {
            case URI_MATCH_HOMEPAGE:
                MatrixCursor cursor = new MatrixCursor(new String[] { "homepage" }, 1);
                cursor.addRow(new Object[] { HOMEPAGE_URI });
                return cursor;
            default:
                return null;
        }
    }

    @Override
    public Uri insert(Uri uri, ContentValues values) {
        throw new UnsupportedOperationException();
    }

    @Override
    public int delete(Uri uri, String selection, String[] selectionArgs) {
        throw new UnsupportedOperationException();
    }

    @Override
    public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
        throw new UnsupportedOperationException();
    }




}

设置百度为默认主页,然后配置Androidmanifest.xml

 <application>
        <provider android:name="PartnerBookmarksProvider"
            android:authorities="com.android.partnerbookmarks" />

        <provider android:name="PartnerHomepageProvider"
            android:authorities="com.android.partnerbrowsercustomizations" />
    </application>

最后再编译 就ok了

相关阅读

这5款功能强大、堪称最良心的浏览器,简直好用极了!

很多小伙伴都用过QQ浏览器、UC浏览器以及搜狗浏览器,除了这些主流的浏览器你还用过哪些呢?今天小编就给大家推荐几款的浏览器,小巧好

安卓init:Android7.0系统Init原理(一)

  【开篇说明】 学习Android第一步便是“init”,作为天字第一号进程,代码羞涩难懂,但是也极其重要,熟悉init的原理对后面Zygote --

Android 禁止fastboot模式

修改bootable/bootloader/lk/app/aboot/aboot.c  else if(reboot_mode == FASTBOOT_MODE) { //boot_into_fastboot = tru

Android O适配

官方文档:https://developer.android.com/preview/features/background.html#migration一、从Android O针对服务以及广播这两个组

20190708_android技术要求

1、android基本组件:Activity,Service,Broadcast,ContentProvider 2、android5.0及以上的新特性 Material Design设计风格:扁平化

分享到:

栏目导航

推荐阅读

热门阅读