谷歌允許合作伙伴客制化Chrome的一些配置,如Chrome瀏覽器預置默認主頁及書簽,當預置成功后,將在狀態欄看到主頁的圖標,可設置主頁、主頁的開啟及關閉,可通過書簽快捷打開對應網頁。
客制化主要通過添加對應ChromeCustomizations.apk(主頁) 及PartnerBookmarksProvider.apk(書簽)來實現,具體實現方法如下:
一、預置chrome默認主頁(http://www.baidu.com)
1)下載homepage_provider_example工程,修改默認主頁URL
文件路徑:src\com\android\partnerbrowsercustomizations\example\PartnerHomepageProviderExample.java
- // 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 <manifest package="..."> in AndroidManifest.xml.
- package com.android.partnerbrowsercustomizations.example;
- import android.content.ContentProvider;
- import android.content.ContentValues;
- import android.content.UriMatcher;
- import android.database.Cursor;
- import android.database.MatrixCursor;
- import android.net.Uri;
- // Class name can be changed, but should match <provider android:name="..."> 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://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) {
- // 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();
- }
- }
2)編譯工程,並push生成的apk到system/vendor/app/ 目錄
由於工程編譯出來的名稱為:homepage_provider_example.apk,所以push時要修改apk的名稱為:ChromeCustomizations.apk,可用以下命令:
adb push homepage_provider_example.apk system/vendor/app/ChromeCustomizations.apk
二、預置默認書簽
1)下載PartnerBookmarksProvider工程(該工程也可在源碼下找到,目錄路徑為:packages\providers\PartnerBookmarksProvider)
2)添加書簽圖片資源,目錄路徑為res\raw
3)添加書簽名稱及對應的網址,目錄路徑為:res\values\strings.xml
- <?xml version="1.0" encoding="utf-8"?>
- <!-- 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.
- -->
- <resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
- <!-- Bookmarks -->
- <string name="bookmarks_folder_name">Default Bookmarks</string>
- <string-array name="bookmarks">
- <item>Google</item>
- <item>http://www.google.com/</item>
- <item>Yahoo</item>
- <item>http://www.yahoo.com/</item>
- <item>Picasa</item>
- <item>http://picasaweb.google.com/</item>
- <item>MSN</item>
- <item>http://www.msn.com/</item>
- <item>Twitter</item>
- <item>http://twitter.com/</item>
- <item>Facebook</item>
- <item>http://www.facebook.com/</item>
- <item>Wikipedia</item>
- <item>http://www.wikipedia.org/</item>
- <item>eBay</item>
- <item>http://www.ebay.com/</item>
- <item>CNN</item>
- <item>http://www.cnn.com/</item>
- <item>NY Times</item>
- <item>http://www.nytimes.com/</item>
- <item>ESPN</item>
- <item>http://espn.com/</item>
- <item>Amazon</item>
- <item>http://www.amazon.com/</item>
- <item>Weather Channel</item>
- <item>http://www.weather.com/</item>
- <item>BBC</item>
- <item>http://www.bbc.co.uk/</item>
- </string-array>
- </resources>
4)添加書簽對應的圖標,目錄路徑為:res\values\bookmarks_icons.xml
- <?xml version="1.0" encoding="utf-8"?>
- <!-- 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.
- -->
- <resources>
- <array name="bookmark_preloads">
- <item>@raw/favicon_google</item>
- <item>@raw/touch_google</item>
- <item>@raw/favicon_yahoo</item>
- <item>@raw/thumb_yahoo</item>
- <item>@raw/favicon_picasa</item>
- <item>@raw/thumb_picasa</item>
- <item>@raw/favicon_msn</item>
- <item>@raw/thumb_msn</item>
- <item>@raw/favicon_twitter</item>
- <item>@raw/thumb_twitter</item>
- <item>@raw/favicon_facebook</item>
- <item>@raw/thumb_facebook</item>
- <item>@raw/favicon_wikipedia</item>
- <item>@raw/thumb_wikipedia</item>
- <item>@raw/favicon_ebay</item>
- <item>@raw/thumb_ebay</item>
- <item>@raw/favicon_cnn</item>
- <item>@raw/thumb_cnn</item>
- <item>@raw/favicon_nytimes</item>
- <item>@raw/thumb_nytimes</item>
- <item>@raw/favicon_espn</item>
- <item>@raw/thumb_espn</item>
- <item>@raw/favicon_amazon</item>
- <item>@raw/thumb_amazon</item>
- <item>@raw/favicon_weatherchannel</item>
- <item>@raw/thumb_weatherchannel</item>
- <item>@raw/favicon_bbc</item>
- <item>@raw/thumb_bbc</item>
- </array>
- </resources>
5)編譯工程,並把工程push到system/app目錄下,可用以下命令:
adb push PartnerBookmarksProvider.apk system/app
三、最終結果: