預置Chrome瀏覽器默認主頁和書簽


  谷歌允許合作伙伴客制化Chrome的一些配置,如Chrome瀏覽器預置默認主頁及書簽,當預置成功后,將在狀態欄看到主頁的圖標,可設置主頁、主頁的開啟及關閉,可通過書簽快捷打開對應網頁。

       客制化主要通過添加對應ChromeCustomizations.apk(主頁) 及PartnerBookmarksProvider.apk(書簽)來實現,具體實現方法如下:

一、預置chrome默認主頁(http://www.baidu.com)

1)下載homepage_provider_example工程,修改默認主頁URL

       文件路徑:src\com\android\partnerbrowsercustomizations\example\PartnerHomepageProviderExample.java

[java] view plain copy 在CODE上查看代碼片 派生到我的代碼片
  1. // Copyright 2013 The Chromium Authors. All rights reserved.  
  2. // Use of this source code is governed by a BSD-style license that can be  
  3. // found in the LICENSE file.  
  4.   
  5. // Package path can be changed, but should match <manifest package="..."> in AndroidManifest.xml.  
  6. package com.android.partnerbrowsercustomizations.example;  
  7.   
  8. import android.content.ContentProvider;  
  9. import android.content.ContentValues;  
  10. import android.content.UriMatcher;  
  11. import android.database.Cursor;  
  12. import android.database.MatrixCursor;  
  13. import android.net.Uri;  
  14.   
  15. // Class name can be changed, but should match <provider android:name="..."> in AndroidManifest.xml.  
  16. public class PartnerHomepageProviderExample extends ContentProvider {  
  17.     // "http://www.android.com/" is just an example. Please replace this to actual homepage.  
  18.     // Other strings in this class must remain as it is.  
  19.     private static String HOMEPAGE_URI = "http://www.baidu.com";  
  20.     private static final int URI_MATCH_HOMEPAGE = 0;  
  21.     private static final UriMatcher URI_MATCHER = new UriMatcher(UriMatcher.NO_MATCH);  
  22.     static {  
  23.         URI_MATCHER.addURI("com.android.partnerbrowsercustomizations", "homepage",  
  24.                 URI_MATCH_HOMEPAGE);  
  25.     }  
  26.   
  27.     @Override  
  28.     public boolean onCreate() {  
  29.         return true;  
  30.     }  
  31.   
  32.     @Override  
  33.     public String getType(Uri uri) {  
  34.         // In fact, Chrome does not call this.  
  35.         // Just a recommaned ContentProvider practice in general.  
  36.         switch (URI_MATCHER.match(uri)) {  
  37.             case URI_MATCH_HOMEPAGE:  
  38.                 return "vnd.android.cursor.item/partnerhomepage";  
  39.             default:  
  40.                 return null;  
  41.         }  
  42.     }  
  43.   
  44.     @Override  
  45.     public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,  
  46.             String sortOrder) {  
  47.         switch (URI_MATCHER.match(uri)) {  
  48.             case URI_MATCH_HOMEPAGE:  
  49.                 MatrixCursor cursor = new MatrixCursor(new String[] { "homepage" }, 1);  
  50.                 cursor.addRow(new Object[] { HOMEPAGE_URI });  
  51.                 return cursor;  
  52.             default:  
  53.                 return null;  
  54.         }  
  55.     }  
  56.   
  57.     @Override  
  58.     public Uri insert(Uri uri, ContentValues values) {  
  59.         throw new UnsupportedOperationException();  
  60.     }  
  61.   
  62.     @Override  
  63.     public int delete(Uri uri, String selection, String[] selectionArgs) {  
  64.         throw new UnsupportedOperationException();  
  65.     }  
  66.   
  67.     @Override  
  68.     public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {  
  69.         throw new UnsupportedOperationException();  
  70.     }  
  71.   
  72. }  

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

[html] view plain copy 在CODE上查看代碼片 派生到我的代碼片
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <!-- Copyright (C) 2012 The Android Open Source Project  
  3.   
  4.      Licensed under the Apache License, Version 2.0 (the "License");  
  5.      you may not use this file except in compliance with the License.  
  6.      You may obtain a copy of the License at  
  7.   
  8.           http://www.apache.org/licenses/LICENSE-2.0  
  9.   
  10.      Unless required by applicable law or agreed to in writing, software  
  11.      distributed under the License is distributed on an "AS IS" BASIS,  
  12.      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
  13.      See the License for the specific language governing permissions and  
  14.      limitations under the License.  
  15. -->  
  16.   
  17. <resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">  
  18.     <!-- Bookmarks -->  
  19.     <string name="bookmarks_folder_name">Default Bookmarks</string>  
  20.     <string-array name="bookmarks">  
  21.         <item>Google</item>  
  22.         <item>http://www.google.com/</item>  
  23.         <item>Yahoo</item>  
  24.         <item>http://www.yahoo.com/</item>  
  25.         <item>Picasa</item>  
  26.         <item>http://picasaweb.google.com/</item>  
  27.         <item>MSN</item>  
  28.         <item>http://www.msn.com/</item>  
  29.         <item>Twitter</item>  
  30.         <item>http://twitter.com/</item>  
  31.         <item>Facebook</item>  
  32.         <item>http://www.facebook.com/</item>  
  33.         <item>Wikipedia</item>  
  34.         <item>http://www.wikipedia.org/</item>  
  35.         <item>eBay</item>  
  36.         <item>http://www.ebay.com/</item>  
  37.         <item>CNN</item>  
  38.         <item>http://www.cnn.com/</item>  
  39.         <item>NY Times</item>  
  40.         <item>http://www.nytimes.com/</item>  
  41.         <item>ESPN</item>  
  42.         <item>http://espn.com/</item>  
  43.         <item>Amazon</item>  
  44.         <item>http://www.amazon.com/</item>  
  45.         <item>Weather Channel</item>  
  46.         <item>http://www.weather.com/</item>  
  47.         <item>BBC</item>  
  48.         <item>http://www.bbc.co.uk/</item>  
  49.     </string-array>  
  50. </resources>  

4)添加書簽對應的圖標,目錄路徑為:res\values\bookmarks_icons.xml

[html] view plain copy 在CODE上查看代碼片 派生到我的代碼片
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <!-- Copyright (C) 2012 The Android Open Source Project  
  3.   
  4.      Licensed under the Apache License, Version 2.0 (the "License");  
  5.      you may not use this file except in compliance with the License.  
  6.      You may obtain a copy of the License at  
  7.   
  8.           http://www.apache.org/licenses/LICENSE-2.0  
  9.   
  10.      Unless required by applicable law or agreed to in writing, software  
  11.      distributed under the License is distributed on an "AS IS" BASIS,  
  12.      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
  13.      See the License for the specific language governing permissions and  
  14.      limitations under the License.  
  15. -->  
  16.   
  17. <resources>  
  18.     <array name="bookmark_preloads">  
  19.         <item>@raw/favicon_google</item>  
  20.         <item>@raw/touch_google</item>  
  21.         <item>@raw/favicon_yahoo</item>  
  22.         <item>@raw/thumb_yahoo</item>  
  23.         <item>@raw/favicon_picasa</item>  
  24.         <item>@raw/thumb_picasa</item>  
  25.         <item>@raw/favicon_msn</item>  
  26.         <item>@raw/thumb_msn</item>  
  27.         <item>@raw/favicon_twitter</item>  
  28.         <item>@raw/thumb_twitter</item>  
  29.         <item>@raw/favicon_facebook</item>  
  30.         <item>@raw/thumb_facebook</item>  
  31.         <item>@raw/favicon_wikipedia</item>  
  32.         <item>@raw/thumb_wikipedia</item>  
  33.         <item>@raw/favicon_ebay</item>  
  34.         <item>@raw/thumb_ebay</item>  
  35.         <item>@raw/favicon_cnn</item>  
  36.         <item>@raw/thumb_cnn</item>  
  37.         <item>@raw/favicon_nytimes</item>  
  38.         <item>@raw/thumb_nytimes</item>  
  39.         <item>@raw/favicon_espn</item>  
  40.         <item>@raw/thumb_espn</item>  
  41.         <item>@raw/favicon_amazon</item>  
  42.         <item>@raw/thumb_amazon</item>  
  43.         <item>@raw/favicon_weatherchannel</item>  
  44.         <item>@raw/thumb_weatherchannel</item>  
  45.         <item>@raw/favicon_bbc</item>  
  46.         <item>@raw/thumb_bbc</item>  
  47.     </array>  
  48. </resources>  

5)編譯工程,並把工程push到system/app目錄下,可用以下命令:

adb push PartnerBookmarksProvider.apk system/app

三、最終結果:



免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM