Chrome浏览器定制主页和书签

因为google为了扩大chrome浏览器的范围还有影响,所以在很早以前就开始充许客户订制主页和书签,这个其中主要使用了ContentProvider的特性进行数据的分享。

在google提供的源码中有定制主页和书签的apk,但是在高通和mtk分发的时候这两个apk已经做了一定的处理,不在进行编译。其中两个项目都位置在:packages/providers下

一,定制主页

定制主页google给的项目名称是ChromeCustomizations,这个项目只是一个ContentProvider,然后提供一个数据给chrome,其实两个项目都是如此

具体代码:

// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Package path can be changed, but should match  in AndroidManifest.xml.
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;
import android.os.Build;

// Class name can be changed, but should match  in AndroidManifest.xml.
public class PartnerHomepageProviderExample extends ContentProvider {
    // "http://www.android.com/" is just an example. Please replace this to actual homepage.
    // Other strings in this class must remain as it is.
     private static String HOMEPAGE_URI="http://o";
    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) {
        // In fact, Chrome does not call this.
        // Just a recommaned ContentProvider practice in general.
        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 中进行注册,这样我们就能给chrome数据了,其实这个不用单独的使用一个apk,加到默认的apk中都能实现此功能
android:name="PartnerHomepageProviderExample"
    android:authorities="com.android.partnerbrowsercustomizations" />

二,定制书签:PartnerBookmarksProvider/主要是重写string中的bookmarks数组和bookmarks_icon.xml中的bookmark_preloads数组

  1. <string-array name="bookmarks">  
  2.         <item>Baiduitem>  
  3.         <item>http://www.baidu.com/item>
  4. string-array>
  1. <array name="bookmark_preloads">
  2.  <item>@raw/favicon_baiduitem> 
  3. <item>@raw/thumb_baiduitem>
  4. array>


最后需要说明的是在添加以上数据后,记得在mk文件中把项目添加上,然后在编译系统的时候我们修改才会起到作用

你可能感兴趣的:(android)