chrome主页&书签定制

chrome允许客户主页和书签,通过ContentProvider获取定制的信息,定制APK源码位置:
packages/providers/PartnerBookmarksProvider

书签

添加书签非常简单,只需在xml中添加网址即可。
PartnerBookmarksProvider/res/values/strings.xml

Partner Bookmarks

    baidu
    https://www.baidu.com/
    360
    https://www.so.com/

主页

要自己添加一个PartnerHomepageProvider.java(见下方)放到目录:PartnerBookmarksProvider/src/com/android/providers/partnerbookmarks/
然后在AndroidManifest.xml注册homepage的provider即可。


    

最后,定制主页只需修改PartnerHomepageProvider.java中的HOMEPAGE_URI字段为指定主页网址即可。

// 设置默认的主页网址
private static String HOMEPAGE_URI = "https://www.baidu.com";

PartnerHomepageProvider.java

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;

public class PartnerHomepageProvider extends ContentProvider {
    // 设置默认的主页网址
    private static String HOMEPAGE_URI = "https://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();
    }

}

你可能感兴趣的:(chrome主页&书签定制)