Android chrome浏览器的定制

news/2024/11/29 0:52:40/

最近在做海外项目需要定制chrome浏览器的书签和主页,在8.1的项目上实现,当时手机还没有预制GMS,只能下载chrome 这个apk做实验,出现了很多问题,书签没有作用,安装了gms里面的chrome,主页又没生效,六神无主,经过网上的文档发现,GMS必须预制才能生效

1.预制书签。

预制书签很简单 ,只需要改系统自带的原生代码的目录下

.\packages\providers\PartnerBookmarksProvider

代码 这些都是自带的

src\com\android\providers\partnerbookmark/** 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.*/package com.android.providers.partnerbookmarks;import android.content.ContentProvider;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.UriMatcher;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.database.Cursor;
import android.database.DatabaseUtils;
import android.database.MatrixCursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteQueryBuilder;
import android.net.Uri;
import android.text.TextUtils;
import android.util.Log;import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;/*** Default partner bookmarks provider implementation of {@link PartnerBookmarksContract} API.* It reads the flat list of bookmarks and the name of the root partner* bookmarks folder using getResources() API.** Sample resources structure:*     res/*         values/*             strings.xml*                  string name="bookmarks_folder_name"*                  string-array name="bookmarks"*                      item TITLE1*                      item URL1*                      item TITLE2*                      item URL2...*             bookmarks_icons.xml*                  array name="bookmark_preloads"*                      item @raw/favicon1*                      item @raw/touchicon1*                      item @raw/favicon2*                      item @raw/touchicon2*                      ...*/
public class PartnerBookmarksProvider extends ContentProvider {private static final String TAG = "PartnerBookmarksProvider";// URI matcherprivate static final int URI_MATCH_BOOKMARKS = 1000;private static final int URI_MATCH_BOOKMARKS_ID = 1001;private static final int URI_MATCH_BOOKMARKS_FOLDER = 1002;private static final int URI_MATCH_BOOKMARKS_FOLDER_ID = 1003;private static final int URI_MATCH_BOOKMARKS_PARTNER_BOOKMARKS_FOLDER_ID = 1004;private static final UriMatcher URI_MATCHER = new UriMatcher(UriMatcher.NO_MATCH);private static final Map<String, String> BOOKMARKS_PROJECTION_MAP= new HashMap<String, String>();// Default sort order for unsync'd bookmarksprivate static final String DEFAULT_BOOKMARKS_SORT_ORDER =PartnerBookmarksContract.Bookmarks.ID + " DESC, "+ PartnerBookmarksContract.Bookmarks.ID + " ASC";// Initial bookmark id when for getResources() importing// Make sure to fix tests if you are changing thisprivate static final long FIXED_ID_PARTNER_BOOKMARKS_ROOT =PartnerBookmarksContract.Bookmarks.BOOKMARK_PARENT_ROOT_ID + 1;// DB table nameprivate static final String TABLE_BOOKMARKS = "bookmarks";static {final UriMatcher matcher = URI_MATCHER;final String authority = PartnerBookmarksContract.AUTHORITY;matcher.addURI(authority, "bookmarks", URI_MATCH_BOOKMARKS);matcher.addURI(authority, "bookmarks/#", URI_MATCH_BOOKMARKS_ID);matcher.addURI(authority, "bookmarks/folder", URI_MATCH_BOOKMARKS_FOLDER);matcher.addURI(authority, "bookmarks/folder/#", URI_MATCH_BOOKMARKS_FOLDER_ID);matcher.addURI(authority, "bookmarks/folder/id",URI_MATCH_BOOKMARKS_PARTNER_BOOKMARKS_FOLDER_ID);// Projection mapsMap<String, String> map = BOOKMARKS_PROJECTION_MAP;map.put(PartnerBookmarksContract.Bookmarks.ID,PartnerBookmarksContract.Bookmarks.ID);map.put(PartnerBookmarksContract.Bookmarks.TITLE,PartnerBookmarksContract.Bookmarks.TITLE);map.put(PartnerBookmarksContract.Bookmarks.URL,PartnerBookmarksContract.Bookmarks.URL);map.put(PartnerBookmarksContract.Bookmarks.TYPE,PartnerBookmarksContract.Bookmarks.TYPE);map.put(PartnerBookmarksContract.Bookmarks.PARENT,PartnerBookmarksContract.Bookmarks.PARENT);map.put(PartnerBookmarksContract.Bookmarks.FAVICON,PartnerBookmarksContract.Bookmarks.FAVICON);map.put(PartnerBookmarksContract.Bookmarks.TOUCHICON,PartnerBookmarksContract.Bookmarks.TOUCHICON);}...................
...................
...................@Overridepublic String getType(Uri uri) {final int match = URI_MATCHER.match(uri);if (match == UriMatcher.NO_MATCH) return null;return PartnerBookmarksContract.Bookmarks.CONTENT_ITEM_TYPE;}@Overridepublic int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {throw new UnsupportedOperationException();}
}

代码里面有注释 ,只需要修改一下 res/values的资源就可以实现书签的定制

这里写图片描述

strings.xml<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"><string name="bookmarks_folder_name" translatable="false">Partner Bookmarks</string><string-array name="bookmarks" ><item>Goolgle</item><item>http://www.google.com/</item>  </string-array>
</resources>
bookmarks_icons.xml<resources><array name="bookmark_preloads" ><item>@raw/a</item><item>@raw/b</item></array>
</resources>

只需要配置好,书签可以配置成功

2.主页配置

从网上下载代码 放入到
这里写图片描述
同级目录下

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;/*** Created by linl@x-thinks.com 2018/3/12.*/public class PartnerHomepageProvider extends ContentProvider {// 设置默认的主页网址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);}@Overridepublic boolean onCreate() {return true;}@Overridepublic String getType(Uri uri) {switch (URI_MATCHER.match(uri)) {case URI_MATCH_HOMEPAGE:return "vnd.android.cursor.item/partnerhomepage";default:return null;}}@Overridepublic 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;}}@Overridepublic Uri insert(Uri uri, ContentValues values) {throw new UnsupportedOperationException();}@Overridepublic int delete(Uri uri, String selection, String[] selectionArgs) {throw new UnsupportedOperationException();}@Overridepublic int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {throw new UnsupportedOperationException();}}

设置百度为默认主页,然后配置AndroidManifest.xml

 <application><provider android:name="PartnerBookmarksProvider"android:authorities="com.android.partnerbookmarks" /><provider android:name="PartnerHomepageProvider"android:authorities="com.android.partnerbrowsercustomizations" /></application>

最后再编译 就ok了


http://www.ppmy.cn/news/662183.html

相关文章

外贸人必备GoogleChrome浏览器插件推荐(一)

图片来源&#xff1a;图虫创意 谷歌旗下牛逼的产品很多&#xff0c;Google Chrome浏览器是其中一个&#xff0c;这个浏览器是目前的CEO劈柴哥带队开发的&#xff0c;这是Pichai兄加入谷歌后开发的第一款产品。 从这款产品我们就能看出为什么Pichi能够当上谷歌的CEO。 谷歌浏…

谷歌浏览器 android4.4,谷歌发布移动版Chrome浏览器仅限Android4.0

谷歌已经针对Android手机推出了移动版Chrome浏览器 演示视频截图 谷歌已经针对Android手机推出了移动版Chrome浏览器Chrome for Android Beta&#xff0c;不过目前还只限于Android 4.0系统。 移动版Chrome运行速度更快&#xff0c;可以同步任何内容&#xff0c;标签之间的转换更…

chrome linux arm64,谷歌浏览器为何还没发布ARM64原生版?高通表示非技术而是政策问题...

高通与微软合作的Windows 10 ARM 设备目前发展并不顺利&#xff0c;尽管愿景很美好但愿购买此类设备的用户并不多。 用户不愿意购买的原因其实有多种&#xff0c;但是可能最大的问题就是此类设备的兼容性并没有传统笔记本电脑的那么好。 例如传统桌面软件理论上说是不支持此类A…

horace

生活有梦想&#xff0c;就不畏惧 短暂的寒冷。

为什么会有跨域?跨域的原因是什么?

原文链接&#xff1a;https://www.zhihu.com/question/31592553 跨域springmvc http://blog.csdn.net/wabiaozia/article/details/52778335 跨域&#xff1a;ajax跨域&#xff0c;这应该是最全的解决方案了http://web.jobbole.com/93344/ 阮一峰 跨域资源共享 CORS 详解&…

mysql使用mycat读写分离时,报 Connection is read-only. Queries leading to data modification are not allo

解决方法 MySQL自身会对只读事务做优化&#xff0c;这是MySQL5.6.5 版本以后才出现的。 http://dev.mysql.com/doc/refman/5.6/en/server-system-variables.html#sysvar_tx_read_only useLocalSessionState解释及影响 1.描述 useLocalSessionState:驱动程序是否应引用autocom…

面试 ---集合(三)ConcurrentHashMap原理分析

https://my.oschina.net/hosee/blog/639352 https://blog.csdn.net/u011328417/article/details/79284730 http://www.importnew.com/28263.html http://www.importnew.com/22007.html HashTable是一个线程安全的类&#xff0c;它使用synchronized来锁住整张Hash表来实现线…

SEE

SSE是英特尔提出的即MMX之后新一代&#xff08;当然是几年前了&#xff09;CPU指令集&#xff0c;最早应用在PIII系列CPU上。现在已经得到了Intel PIII、P4、Celeon、Xeon、AMD Athlon、duron等系列CPU的支持。而更新的SSE2指令集仅得到了P4系列CPU的支持&#xff0c;这也是为什…