轻源码

  • QingYuanMa.com
  • 全球最大的互联网技术和资源下载平台
搜索
一起源码网 门户 微端制作 查看主题

Android开发_如何调用 微端访问网页和Html文件

发布者: 逍遥 | 发布时间: 2018-1-11 23:01| 查看数: 1719| 评论数: 1|帖子模式

一、启动android默认微端

 

    Intent intent= new Intent();        
    intent.setAction("android.intent.action.VIEW");    
    Uri content_url = Uri.parse("");   
    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("");   
                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“这个形式了


有兴趣的可以去试试。 

最新评论

xwiom 发表于 2022-5-9 17:38
html网页制作源码免费

轻源码让程序更轻更快

QingYuanMa.com

工作时间 周一至周六 8:00-17:30

侵权处理

客服QQ点击咨询

关注抖音号

定期抽VIP

Copyright © 2016-2021 https://www.171739.xyz/ 滇ICP备13200218号

快速回复 返回顶部 返回列表