系统定制修改之修改 chrome 浏览器默认主页为指定网址

原文链接:点击打开链接

步骤1定义一个java类 PartnerHomepageProviderExample.java 文件,代码如下:

定义好之后拷贝到源码环境该目录下: \packages\providers\PartnerBookmarksProvider\src\com\android\providers\partnerbookmarks\PartnerHomepageProviderExample.java 

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;


public class PartnerHomepageProviderExample extends ContentProvider {
    // 设置默认的主页网址
    private static String HOMEPAGE_URI = "http://www.google.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) {
        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();
    }

}

找到定义AndroidManifet.xml文件, 路径: \packages\providers\PartnerBookmarksProvider\AndroidManifest.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.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.android.providers.partnerbookmarks">

    <!-- We add an application tag here just to indicate the authorities -->
    <application>
        <provider android:name="PartnerBookmarksProvider"
            android:authorities="com.android.partnerbookmarks" />
        <!--add begin. config provider-->
        <provider android:name="PartnerHomepageProviderExample"
             android:authorities="com.android.partnerbrowsercustomizations" />
        <!-- add end -->
    </application>
    <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="14" />
</manifest>





展开阅读全文

没有更多推荐了,返回首页