就是查看一下本机上可用的浏览器,因为之前做过检测语音识别程序时需要检测Google 语音命令,这里简单的修改了一下就可以查看了。
具体代码如下:
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.2cto.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"); } } }
输出结果为:
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.dolphin.browser.BrowserActivity