Android开发_如何调用系统默认浏览器访问
http://blog.sina.com.cn/s/blog_6efce07e010142w7.html
一、启动android默认浏览器
Intent intent= new Intent();
intent.setAction("android.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");
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开发中怎样调用系统Email发送邮件(多种调用方式)
在Android中调用其他程序进行相关处理,几乎都是使用的Intent,所以,Email也不例外,所谓的调用Email,只是说Email可以接收Intent并做这些事情 我们都知道,在Android中 ...
- [Android] 图片裁剪总结——调用系统裁剪
花了两天时间看了下android的图片裁剪功能的实现.其实刚开始做这个我挺虚的,以为整个功能都需要自己写出来,但查了些资料,发现android已经提供了裁剪功能,需要的话自己调用就成了.soga,这下 ...
- Android开发_*.R文件无法自动生成
问题描述: 今天是我决定专注Android开发的第一天,我在网上下载了一个数独游戏的源码,准备开始着手学习.在导入之后出现Java文件中import *.R文件报错,在gen目 ...
- Android开发心得-使用File ExPlorer无法访问系统内部文件
问题:本机在获得ROOT权限后,使用Eclipse自带的File Explorer访问/data/data下各APP的存储文件,均无法打开.更换另外一个设备后,情况正常.Sumsung的有些机型在获得 ...
- Android开发中如何调用摄像头的功能
我们要调用摄像头的拍照功能,显然 第一步必须加入调用摄像头硬件的权限,拍完照后我们要将图片保存在SD卡中,必须加入SD卡读写权限,所以第一步,我们应该在Android清单文件中加入以下代码 & ...
- Android开发系列之调用WebService
我在学习Android开发过程中遇到的第一个疑问就是Android客户端是怎么跟服务器数据库进行交互的呢?这个问题是我当初初次接触Android时所困扰我的一个很大的问题,直到几年前的一天,我突然想到 ...
- android开发 Fragment嵌套调用常见错误
在activity中有时须要嵌套调用fragment,但嵌套调用往往带来视图的显示与预期的不一样或是fragment的切换有问题.在使用时要注意几点: 1.fragment中嵌套fragment,子f ...
- Android开发_后台任务task管理_allowTaskReparenting alwaysRetainTaskState clearTaskOn
1.android:allowTaskReparenting 这个属性用来标记一个Activity实例在当前应用退居后台后,是否能从启动它的那个task移动到有共同affinity的task,“tru ...
- Android开发_关于中英文切换
开发APP过程中可能要有中文模式和英文模式,切换后控件要随着进行更改,以下代码可以很好的实现: public static int getResourcesId(Context context, St ...
随机推荐
- angular 样式属性绑定
<button (click)="onClick($event)">点我</button> <input type="> <ta ...
- mysql 新建数据库与表
- 【大数据之数据仓库】GreenPlum优化器对比测试
在< [大数据之数据仓库]选型流水记>一文中有提及,当时没有测试GreenPlum的quicklz压缩算法和ORCA查询优化器,考虑到quicklz压缩算法因为版权问题不会开源(详情请参阅 ...
- C# LINQ(5)
目前都是说的单数据差距,如果多数据进行查询LINQ该如何呢? 那么LINQ就应该使用关键字 join on equals 现有代码: static void Main(string[] args) { ...
- fputs()
原型:int fputs(const char *str, FILE *stream) 参数解释: const char *str : const限制函数内部修改指针指向的数据(在函数形参使用cons ...
- [Algorithm]查找
一.查找的算法 1.顺序查找 1 int Search_Seq( SeqList L, ElemType elem ) 2 { 3 L.elem[0] = elem; 4 for ( int i = ...
- Ext中setValue和setRawValue
Ext.getCmp('modifyStatus').setValue(record.get('status').trim()); Ext.getCmp('modifyStatus').setRawV ...
- Python正则表达式匹配日期与时间
#!/usr/bin/env python # -*- coding: utf-8 -*- __author__ = 'Randy' import re from datetime import da ...
- Win通过端口号结束进程
准备: 01在cmd中查看命令使用 格式:命令名称 /? 02netstat 03findstr C:\Users\Good>findstr /? 在文件中寻找字符串. ...... strin ...
- CodeForces - 233A Perfect Permutation
A. Perfect Permutation time limit per test: 2 seconds memory limit per test: 256 megabytes input: st ...