android启动时自动设置默认浏览器
PackageManagerService.java添加如下代码:在frameworks\base下
From 006ba2ccaca761ffc67f35cac551f6ca9008f8b7 Mon Sep 17 00:00:00 2001
From: weitf weitf@klinktek.com
Date: Tue, 13 Oct 2015 09:45:43 +0800
Subject: [PATCH 1/3] setDefaultBrowser
…/android/server/pm/PackageManagerService.java | 63 ++++++++++++++++++++
1 file changed, 63 insertions(+)
diff –git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java
index 6f88399..9c1fd17 100755
— a/services/core/java/com/android/server/pm/PackageManagerService.java
+++ b/services/core/java/com/android/server/pm/PackageManagerService.java
@@ -1858,6 +1858,8 @@ public class PackageManagerService extends IPackageManager.Stub {
// are all flushed. Not really needed, but keeps things nice and
// tidy.
Runtime.getRuntime().gc();
+
+ setDefaultBrowser();
}
//$_rockchip_$_modify_by huangjc add copyPackagesToAppInstallDir
@@ -14131,4 +14133,65 @@ public class PackageManagerService extends IPackageManager.Stub {
}
mSettings.writeLPr();
}
+
+ //added by inet_weitf @20151013
+ private final void setDefaultBrowser(){
+ Log.d(“debug_default”,”setDefaultBrowser is called.”);
+ if(!isFirstBoot()) {
+ Log.d(“debug_default”,”not first boot, return”);
+ return;
+ }
+ String str1 = “android.intent.category.DEFAULT”;
+ String str2 = “android.intent.category.BROWSABLE”;
+ String str3 = “android.intent.action.VIEW”;
+ //intent filter
+ IntentFilter filter = new IntentFilter(str3);
+ filter.addCategory(str1);
+ filter.addCategory(str2);
+ filter.addDataScheme(“http”);
+ //intent
+ Intent intent = new Intent(str3);
+ intent.addCategory(str2);
+ intent.addCategory(str1);
+ Uri uri = Uri.parse(“http://”);
+ intent.setDataAndType(uri, null);
+ //set UC,if your want set other browser as default, modify below code, add package name and activiy name
+ ComponentName component = new ComponentName(“com.android.browser”,”com.android.browser.BrowserActivity”);
+ //find all browsers
+ List resolveInfoList = queryIntentActivities(intent,intent.getType(),PackageManager.GET_INTENT_FILTERS, 0);
+ int size = resolveInfoList.size();
+ ComponentName[] arrayOfComponentName = new ComponentName[size];
+ //make sure the default browser in phone
+ boolean no_Browser = true;
+ for (int i = 0; i < size; i++){
+ ActivityInfo activityInfo = resolveInfoList.get(i).activityInfo;
+ String packageName = activityInfo.packageName;
+ String className = activityInfo.name;
+ //if your want set other browser as default, modify below package name
+ if (packageName.equals(“com.android.browser”)) no_Browser = false;
+ ComponentName componentName = new ComponentName(packageName, className);
+ arrayOfComponentName[i] = componentName;
+ }
+ if (no_Browser){
+ Log.d(“debug_default”,”no browser package”);
+ return;
+ }else{
+ Log.d(“debug_default”,”browser package is in, set it as Preferred.”);
+ }
+ //set default
+ addPreferredActivity2(filter,IntentFilter.MATCH_CATEGORY_SCHEME, arrayOfComponentName,component);
+ Log.d(“debug_default”,”add browser to PreferredActivity”);
+ }
+
+
+ public void addPreferredActivity2(IntentFilter filter, int match,ComponentName[] set, ComponentName activity) {
+ Log.d(“debug_default”,”addPreferredActivity2 is called.”);
+ // writer
+ synchronized (mPackages) {
+ Slog.i(TAG, “Adding preferred activity ” + activity + “:”);
+ filter.dump(new LogPrinter(Log.INFO, TAG), ” “);
+ mSettings.editPreferredActivitiesLPw(0).addFilter(new PreferredActivity(filter, match, set, activity,true));
+ mSettings.writePackageRestrictionsLPr(0);
+ }
+ }
}
1.7.9.5