I just saw an Android interview question: if you use a browser to open the webpage.
All the explanations on the Internet are simple. Actually, they are very simple. You can set intent. However, here we will explain some additional knowledge.
Check the available browsers on the local machine. Because Google Voice commands need to be detected when detecting the speech recognition program, you can simply modify it here.
The Code is as follows:
Package com. google. code. cakedroid. demo;
Import java. util. List;
Import com. google. code. cakedroid. R;
Import android. app. Activity;
Import android. content. Intent;
Import android. content. pm. PackageManager;
Import android. content. pm. ResolveInfo;
Import android.net. Uri;
Import android. OS. Bundle;
Public class BrowserDemo extends Activity {
@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main );
// Get the view web intent
Intent intent = this. getViewWebIntent ();
This. printInterestedActivitiesByIntent (intent );
// Set the className to use the specific browser to open the webpage.
Intent. setClassName ("com. tencent. mtt", "com. tencent. mtt. MainActivity ");
StartActivity (intent );
}
/*
* Get the desired view web intent
*/
Private Intent getViewWebIntent (){
Intent viewWebIntent = new Intent (Intent. ACTION_VIEW );
Uri uri = Uri. parse ("http://www.bkjia.com ");
ViewWebIntent. setData (uri );
Return viewWebIntent;
}
/*
* Print the activities that are interested about the intent
*/
Private void printInterestedActivitiesByIntent (Intent intent ){
PackageManager pm = this. getPackageManager ();
List <ResolveInfo> activities = pm. queryIntentActivities (intent, 0 );
If (null! = Activities ){
For (int I = 0; I <activities. size (); I ++ ){
ResolveInfo info = activities. get (I );
System. out. println (info. activityInfo. name );
}
} Else {
System. out. println ("no interested activities ");
}
}
}
Output result:
12-17 05:02:30. 096: I/System. out (217): com. android. browser. BrowserActivity
12-17 05:02:30. 096: I/System. out (217): com. tencent. mtt. MainActivity
12-17 05:02:30. 096: I/System. out (217): cn. doldolphin. browser. BrowserActivity
Column Excerpt from BossDarcy