码迷,mamicode.com
首页 > 其他好文 > 详细

预置Chrome浏览器默认主页和书签

时间:2014-10-23 16:09:57      阅读:390      评论:0      收藏:0      [点我收藏+]

标签:android   style   blog   http   io   os   ar   java   for   

  谷歌允许合作伙伴客制化Chrome的一些配置,如Chrome浏览器预置默认主页及书签,当预置成功后,将在状态栏看到主页的图标,可设置主页、主页的开启及关闭,可通过书签快捷打开对应网页。

       客制化主要通过添加对应ChromeCustomizations.apk(主页) 及PartnerBookmarksProvider.apk(书签)来实现,具体实现方法如下:

一、预置chrome默认主页(http://www.baidu.com)

1)下载homepage_provider_example工程,修改默认主页URL

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

  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

bubuko.com,布布扣

bubuko.com,布布扣

3)添加书签名称及对应的网址,目录路径为:res\values\strings.xml

  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

  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

三、最终结果:

bubuko.com,布布扣

预置Chrome浏览器默认主页和书签

标签:android   style   blog   http   io   os   ar   java   for   

原文地址:http://www.cnblogs.com/plpdan/p/4045729.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!