• 如何使用指定浏览器打开网页


    就是查看一下本机上可用的浏览器,因为之前做过检测语音识别程序时需要检测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

     

  • 相关阅读:
    js中的数组
    range关键字,map,sync.Map,list
    数组,切片
    类型转换,指针,变量的生命周期,常量,模拟枚举,类型别名和类型定义
    字符串类型及其常用操作
    整数类型,浮点类型,复数,bool类型
    声明,初始化,匿名变量,作用域
    C#并发编程——异步编程基础
    继承、多态、接口
    C#基础
  • 原文地址:https://www.cnblogs.com/vus520/p/2561936.html
Copyright © 2020-2023  润新知