一、启动android默认浏览器
Intent intent = new Intent();
intent.setAction("android.intent.action.VIEW");//Intent.ACTION_VIEW
Uri content_url = Uri.parse("http://www.cnblogs.com");
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("http://www.cnblogs.com");
intent.setData(content_url);
intent.setClassName("com.android.browser","com.android.browser.BrowserActivity");
//上边这一行 有的机子会报not found错误 可能机子root过;那就选择第一种方法吧;
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“这个形式了。
摘自:
http://blog.csdn.net/liws2010/article/details/7452957一、启动android默认浏览器
Intent intent = new Intent();
intent.setAction("android.intent.action.VIEW");//Intent.ACTION_VIEW
Uri content_url = Uri.parse("http://www.cnblogs.com");
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("http://www.cnblogs.com");
intent.setData(content_url);
intent.setClassName("com.android.browser","com.android.browser.BrowserActivity");
//上边这一行 有的机子会报not found错误 可能机子root过;那就选择第一种方法吧;
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 打开浏览器,浏览器快捷方式
包括Android 移动开发基础案例教程课本中第三章实战演练——打开浏览器的源代码,可用Android studio运行,适合初学者学习。
完整的android文件浏览器,可以打开指定文件
Android卸载或删除应用,调用浏览器打开指定网页地址url
微信浏览器打开外部浏览器解决方案,需要的朋友请直接下载
思路: 获取当前目录下的文件列表,然后显示到listview上面,当点击某个文件夹,则重新加载listview的内容为该文件夹下的文件列表,如果点击文件,则选择打开文件...实现和小米自带文件夹浏览器需求的文件夹浏览器实现
在Android中可以调用自带的浏览器,或者指定一个浏览器来打开一个链接。只需要传入一个uri,可以是链接地址。接下来通过本文给大家分享android 自带浏览器打开网页的实现方法,需要的朋友参考下吧
android图片浏览器,实现简单图片浏览功能-android pictureviewer
本例子是一个简单的安卓浏览器项目源码,如果你已经搭建了一个适合手机浏览的服务端网站比如公司主页等,完全可以把这个源码当作外壳来做一个属于自己的“套壳客户端”,也就是套着安卓客户端的壳子实际上是放了一个...
unity和安卓交互调用安卓浏览器拉起应用市场,用于热更大包
最近做的一个Android项目,发现多款4.1操作系统的手机自带的浏览器下载apk后,在消息提示那里点击安装下载完成的apk没人任何效果。经测试发现在手机sd卡中找到下载的apk点击又是可以安装的。 最后针对这个情况做了下...
Android studio利用webview和zxing制作的一款浏览器,带二维码扫描功能,解压后用Android studio能直接打开,附详细信息和教程:https://blog.csdn.net/mountain_hua/article/details/80606461
如果手机本身安装了多个浏览器而又没有设置默认浏览器的话,系统将让用户选择使用哪个浏览器来打开连接。 Uri uri = Uri.parse(https://www.baidu.com); Intent intent = new Intent(Intent.ACTION_VIEW, uri); ...
Android基于WebView的手机浏览器源码,在android studio环境中,简单可用
本文实例讲述了Android开发实现浏览器全屏显示功能。分享给大家供大家参考,具体如下: 业务需求:浏览器设置中支持全屏显示的功能。 分析:只需要在设置界面上增加是否全屏的checkBox , 然后 BrowserActivity 中...
一、启动android默认浏览器 这样子,android就可以调用起手机默认的浏览器访问。 二、指定相应的浏览器访问 1、指定android自带的浏览器访问 ( “com.android.browser”:packagename ;...
android 文件浏览器,可以查看文件,打开图片,MP3等
为了实现与阿里云IoT Studio移动可视化功能的搭配,使用android studio工具,调用腾讯X5浏览器内核,实现了安卓APP打开之后即可显示指定页面的功能。该源代码gradle已经配置好,采用阿里云仓库,速度很快。X5内核...