android:网页使用网址访问activity
来源:互联网 发布:kindle保护套推荐 知乎 编辑:程序博客网 时间:2024/05/01 15:47
网页打开activity有好几种方法,不过现在我主要介绍的是使用网页打开activity。
首先我们都知道的是,网址的格式:content://host:port/path ,比如:http://10.205.1.10:8080/text.html .
在android中我们也可以使用scheme给activity设置这些东西,设置的方法为:
<activity android:name="你的Activity地址" android:exported="true" android:label="@string/title_activity_intent" > <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:host="10.205.1.10" //随你喜欢设置成什么,可以是任何类型的数据 android:scheme="content" />//和host一样 </intent-filter> </activity>代表scheme的网址格式是:
content://com.example.project:8080/folder/subfolder/etc
\---------/ \---------------------------/ \---/ \--------------------------/
scheme host port path
\--------------------------------/
authority
我们就可以直接获取Activity了,
下面是一个demo:
首先是网页:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title></head><body><a href="content://thisisatest:8080?test1=1&test2=2" >test</a> </body></html>然后我们的Activity设置:
<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:host="thisisatest" android:port="8080" android:scheme="content" /> </intent-filter>这样我们就可以跳转了
获取数据的话 我们需要添加一下代码:
<span style="white-space:pre"></span>Intent intent = getIntent();String scheme = intent.getScheme();Uri uri = intent.getData();
<span style="white-space:pre"></span>String id = uri.getQueryParameter("test1");<span style="white-space:pre"></span>String returnurl = uri.getQueryParameter("test2") ;
0 0
- android:网页使用网址访问activity
- android屏蔽长按 网址的Textview跳转访问网页
- android使用webview访问网页
- android:网页访问Activity出现错误:error unknown url scheme
- android:网页访问Activity出现错误:error unknown url scheme
- android 使用代码打开浏览器访问网页
- Android中实现地址栏输入网址能浏览该地址网页源码操作访问网络
- Android Dynamic Action(动态Action)—像访问网页一样地访问Activity
- 使用httpClient访问指定网址
- Android 访问网页
- Android 访问网页
- android访问网页
- Android 访问固定网页
- android打电话/访问网页
- Android访问网页
- 在网页站点使用Ajax访问CAS保护网址时,报not allowed access错误的解决方法
- android 7.0 使用 webview 访问 https 协议的网址,界面显示空白,其他android版本正常。
- Android实现启动浏览器访问网址
- 教你快速高效接入SDK——总体思路和架构
- 单调链凸包
- 损失函数
- linux内核数据结构之kfifo
- android 桌面应用图标修改无效的问题
- android:网页使用网址访问activity
- 大数据,TB、PB、EB,你了解多少?
- 获取 checkbox 和 radio 选定的值,以及设默认值
- linux内核数据结构之链表
- ORA-01219:数据库未打开:仅允许在固定表/视图中查询
- OpenCV中常用函数
- 三大运营商的号段汇总
- Asp.Net 文件加解密
- My97DatePicker