Android从网页中跳转到APP

一、首先要在AndroidManifest.xml中设置一下过滤器,以JumpActivity为例:

<activity android:name=".JumpActivity" >
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />

        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />

        <!-- 在data里设置了scheme和host,则该Activity可以接收和处理类似于"scheme://data/XXX"的链接 -->
        <data
            android:host="data"
            android:scheme="scheme" />
    </intent-filter>
</activity>

二、在JumpActivity中做打开后的处理,用来接收外部的跳转

public class JumpActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Intent intent = getIntent();
        String data = intent.getDataString(); // 接收到网页传过来的数据:scheme://data/xxx
        String[] split = data.split("data/");
        String param = split[1]; // 获取到网页传过来的参数
    }
}

三、我们需要找到html前端,在网页中加入:

如下:index.html

<!DOCTYPE html>
<html>
<body>
<iframe src="scheme://data/param=abc" style="display:none"/>
</body>
</html>

四、实现原理

就Android平台而言,URI主要分三个部分:scheme、authority、path。其中authority又分为host、port。格式如下:
scheme://host:port/path
举个实际的例子:
content://com.example.project:200/folder/subfolder/etc

现在大家应该知道data flag中那些属性的含义了吧:

<data android:host="string"
      android:mimeType="string"
      android:path="string"
      android:pathPattern="string"
      android:pathPrefix="string"
      android:port="string"
      android:scheme="string" />

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值