Android 打开浏览器的不同方法
2013-07-20 14:34
267 查看
一、启动android默认浏览器
Intent intent = new Intent();
intent.setAction("android.intent.action.VIEW");
Uri content_url = Uri.parse("[color=#0066cc]http://www.cnblogs.com[/color]");
intent.setData(content_url);
startActivity(intent);
复制代码
这样子,android就可以调用起手机默认的浏览器访问。
二、指定相应的浏览器访问
1、指定android自带的浏览器访问
(“com.android.browser”:packagename;“com.android.browser.BrowserActivity”:启动主activity)
Intent intent = new Intent();
intent.setAction("android.intent.action.VIEW");
Uri content_url = Uri.parse("[color=#0066cc]http://www.cnblogs.com[/color]");
intent.setData(content_url);
intent.setClassName("com.android.browser","com.android.browser.BrowserActivity"); startActivity(intent);
复制代码
2、启动其他浏览器(当然该浏览器必须安装在机器上)
只要修改以下相应的packagename 和 主启动activity即可调用其他浏览器
intent.setClassName("com.android.browser","com.android.browser.BrowserActivity");
uc浏览器":"com.uc.browser", "com.uc.browser.ActivityUpdate“
opera:"com.opera.mini.android", "com.opera.mini.android.Browser"
qq浏览器:"com.tencent.mtt", "com.tencent.mtt.MainActivity"
复制代码
三、打开本地html文件
打开本地的html文件的时候,一定要指定某个浏览器,而不能采用方式一来浏览,具体示例代码如下
Intent intent = new Intent();
intent.setAction("android.intent.action.VIEW");
Uri content_url = Uri.parse("content://com.android.htmlfileprovider/sdcard/help.html");
intent.setData(content_url);
intent.setClassName("com.android.browser","com.android.browser.BrowserActivity");
startActivity(intent);
复制代码
关键点是调用了”content“这个filter。
以前有在win32编程的朋友,可能会觉得用这种形式”file://sccard/help.html“是否可以,可以很肯定的跟你说,默认的浏览器设置是没有对”file“这个进行解析的,如果要让你的默认android浏览器有这个功能需要自己到android源码修改manifest.xml文件,然后自己编译浏览器代码生成相应的apk包来重新在机器上安装。
大体的步骤如下:
1、打开 packages/apps/Browser/AndroidManifest.xml文件把加到相应的<intent-filter>后面就可以了
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="file" />
</intent-filter>
复制代码
2、重新编译打包,安装,这样子,新的浏览器就支持”file“这个形式了
Intent intent = new Intent();
intent.setAction("android.intent.action.VIEW");
Uri content_url = Uri.parse("[color=#0066cc]http://www.cnblogs.com[/color]");
intent.setData(content_url);
startActivity(intent);
复制代码
这样子,android就可以调用起手机默认的浏览器访问。
二、指定相应的浏览器访问
1、指定android自带的浏览器访问
(“com.android.browser”:packagename;“com.android.browser.BrowserActivity”:启动主activity)
Intent intent = new Intent();
intent.setAction("android.intent.action.VIEW");
Uri content_url = Uri.parse("[color=#0066cc]http://www.cnblogs.com[/color]");
intent.setData(content_url);
intent.setClassName("com.android.browser","com.android.browser.BrowserActivity"); startActivity(intent);
复制代码
2、启动其他浏览器(当然该浏览器必须安装在机器上)
只要修改以下相应的packagename 和 主启动activity即可调用其他浏览器
intent.setClassName("com.android.browser","com.android.browser.BrowserActivity");
uc浏览器":"com.uc.browser", "com.uc.browser.ActivityUpdate“
opera:"com.opera.mini.android", "com.opera.mini.android.Browser"
qq浏览器:"com.tencent.mtt", "com.tencent.mtt.MainActivity"
复制代码
三、打开本地html文件
打开本地的html文件的时候,一定要指定某个浏览器,而不能采用方式一来浏览,具体示例代码如下
Intent intent = new Intent();
intent.setAction("android.intent.action.VIEW");
Uri content_url = Uri.parse("content://com.android.htmlfileprovider/sdcard/help.html");
intent.setData(content_url);
intent.setClassName("com.android.browser","com.android.browser.BrowserActivity");
startActivity(intent);
复制代码
关键点是调用了”content“这个filter。
以前有在win32编程的朋友,可能会觉得用这种形式”file://sccard/help.html“是否可以,可以很肯定的跟你说,默认的浏览器设置是没有对”file“这个进行解析的,如果要让你的默认android浏览器有这个功能需要自己到android源码修改manifest.xml文件,然后自己编译浏览器代码生成相应的apk包来重新在机器上安装。
大体的步骤如下:
1、打开 packages/apps/Browser/AndroidManifest.xml文件把加到相应的<intent-filter>后面就可以了
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="file" />
</intent-filter>
复制代码
2、重新编译打包,安装,这样子,新的浏览器就支持”file“这个形式了
相关文章推荐
- android 使用浏览器打开指定页面的实现方法
- webdriver+selenium+junit,打开不同浏览器方法
- 生成黑白画笔,android使用系统浏览器打开网页,将Bitmap图片存储在本地JPG文件的方法
- android 开发调用内部浏览器打开网页的方法
- 根据浏览器内核判断是web/iOS/android/ipad/iphone 来打开不同的网站或页面
- Android调用默认浏览器打开指定Url的方法实例
- android 浏览器 打开本地html文件的方法
- Android调用默认浏览器打开指定Url的方法实例
- Android 打开浏览器的几种方法
- Android使用Uri打开浏览器的方法
- android 通过浏览器url打开app的设置方法
- Android调用系统自带浏览器打开网页的实现方法
- 【Android基础】Android跳转浏览器打开URL
- android 打开浏览器 WebView
- js判断当前页面用什么浏览器打开的方法
- Android调用适当程序打开文件的万能方法
- Android开发兼容不同分辨率设备的资源命名方法(Supporting Multiple Screens )
- [Android开发] 导入不同版本的project解决方法
- 在ubuntu下android不同版本源码的对比方法
- activity_main.xml 要用 Android Common XML Editor打开,双击的方式直接跳转到浏览器了