Android download starts QQ browser by default

Source: Internet
Author: User

Android download starts QQ browser by default
// Built-in QQ Browser
// Add the following function to the first activity started by the Program:

// Set the default browser to 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 ";


// Set one of the required parameters of the default item. When your operations comply with this filter, the default setting takes effect.
IntentFilter filter = new IntentFilter (str3 );
Filter. addCategory (str1 );
Filter. addCategory (str2 );
Filter. addDataScheme ("http ");
// Key settings: QQ browsing: package name: com. tencent. mtt, Class Name: 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 );


// Find all browser programs currently installed on the mobile phone
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;


// Clear the default settings
PackageManager. clearPackagePreferredActivities (packageName );
ComponentName componentName = new ComponentName (packageName,
ClassName );
ArrayOfComponentName [I] = componentName;
}
PackageManager. addPreferredActivity (filter,
IntentFilter. MATCH_CATEGORY_SCHEME, arrayOfComponentName,
Component );


}


// Call
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main );

SetBroser (); // call the Function
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.