//內置QQ浏覽器
//在程序啟動的第一個activity 中添加如下函數
//設置系統默認浏覽器是QQ浏覽器
private void setBroser(){
PackageManager packageManager = this.getPackageManager();
String str1 = "android.intent.category.DEFAULT";
String str2 = "android.intent.category.BROWSABLE";
String str3 = "android.intent.action.VIEW";
// 設置默認項的必須參數之一,用戶的操作符合該過濾器時,默認設置起效
IntentFilter filter = new IntentFilter(str3);
filter.addCategory(str1);
filter.addCategory(str2);
filter.addDataScheme("http");
// 關鍵 設置QQ浏覽:包名:com.tencent.mtt ,類名:com.tencent.mtt.MainActivity
ComponentName component = new ComponentName("com.tencent.mtt",
"com.tencent.mtt.MainActivity");
Intent intent = new Intent(str3);
intent.addCategory(str2);
intent.addCategory(str1);
Uri uri = Uri.parse("http://");
intent.setDataAndType(uri, null);
// 找出手機當前安裝的所有浏覽器程序
List
resolveInfoList = packageManager
.queryIntentActivities(intent,
PackageManager.GET_INTENT_FILTERS);
int size = resolveInfoList.size();
ComponentName[] arrayOfComponentName = new ComponentName[size];
for (int i = 0; i < size; i++) {
ActivityInfo activityInfo = resolveInfoList.get(i).activityInfo;
String packageName = activityInfo.packageName;
String className = activityInfo.name;
// 清除之前的默認設置
packageManager.clearPackagePreferredActivities(packageName);
ComponentName componentName = new ComponentName(packageName,
className);
arrayOfComponentName[i] = componentName;
}
packageManager.addPreferredActivity(filter,
IntentFilter.MATCH_CATEGORY_SCHEME, arrayOfComponentName,
component);
}
//調用
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setBroser();//調用函數
}