有时候运营作活动,会给用户送一些东西,用户一领取就会跳到客户端的某个页面,下面记录一下实现过程。
1.Android端实现:
这里用到scheme协议,相似http协议。在Manifest文件里面,找到指定的activity,添加intent-filter,设置data的scheme,host,path等。这些参数的做用是设置这个页面的外部路径,格式为:scheme://host:port/path?qureyParameter=queryString。html
<activity android:name=".ui.activity.NoticeCenterActivity" android:launchMode="singleTop" android:screenOrientation="portrait" android:theme="@style/secondActivityTheme"> <intent-filter> <!--必有项--> <action android:name="android.intent.action.VIEW"/> <!--若是但愿该应用能够经过浏览器的链接启动,则添加该项--> <category android:name="android.intent.category.BROWSABLE"/> <!--表示该页面能够被隐式调用,必须加上该项--> <category android:name="android.intent.category.DEFAULT"/> <!--协议部分--> <data android:scheme="app" android:host="android" android:path="/test" /> </intent-filter> </activity>
配置好了以后,这个页面在网页中的路径,就对应为app://android/test。PS:不必定是全路径,若是只设置了前面的路径,匹配成功的话,也会跳转
这里面要注意的地方有,路径不要以数字开头,<intent-filter>须要添加action等标签。
而后能够在改Activity里面,经过intent获取传参。android
Uri uri=getIntent().getData(); uri.getQueryParameter("id");
2.网页里面调起Android原生页面:
给按钮添加连接地址,就能够打开指定的APP页面了,固然前提是用户手机安装了APP。浏览器
<!DOCTYPE html> <html> <head> <title>从外部网页调起Android原生页面</title> </head> <body> <!--scheme://host:port/path?qureyParameter=queryString--> <a href="app://android/test?id=1">Test</a> </body> </html>
参考连接:http://www.jianshu.com/p/1cd02fe1810f
http://www.jianshu.com/p/7b09cbac1df4app