从外部网页调起Android原生页面

有时候运营做活动,会给用户送一些东西,用户一领取就会跳到客户端的某个页面,下面记录一下实现过程。
1.Android端实现:
这里用到scheme协议,类似http协议。在Manifest文件里面,找到指定的activity,添加intent-filter,设置data的scheme,host,path等。这些参数的作用是设置这个页面的外部路径,格式为:scheme://host:port/path?qureyParameter=queryString。

       <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获取传参。

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/7b09cbac1df4

转载于:https://my.oschina.net/u/2606060/blog/1586261

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值