packages/providers/PartnerBookmarksProvider/src/com/android/providers/partnerbookmarks/PartnerHomepageProvider.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;
/**
* 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);
}
@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();
}
}
然后配置AndroidManifest.xml
<application>
<provider android:name="PartnerBookmarksProvider"
android:authorities="com.android.partnerbookmarks" />
+<provider android:name="PartnerHomepageProvider"
+ android:authorities="com.android.partnerbrowsercustomizations" />
</application>