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


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

     

  • 相关阅读:
    destroy-method="close"
    2.2 Spring的结构组成--Spring源码深度解析
    2.1 Spring容器的基本实现--Spring源码深度解析
    1.2 Spring环境搭建--Spring源码深度解析
    1.1 Spring的整体架构--Spring源码深度解析
    迟到的2016年计划
    spring学习 之helloworld
    从零实现DNN 探究梯度下降的原理
    Java注解——这些@圈圈都是个啥?
    自动发送日报,骗过你的领导^-^
  • 原文地址:https://www.cnblogs.com/vus520/p/2561936.html
Copyright © 2020-2023  润新知