美文网首页
Android 中Scheme协议的使用

Android 中Scheme协议的使用

作者: 程序员阿兵 | 来源:发表于2019-07-11 10:00 被阅读0次

[TOC]

1.介绍

项目中需要支持跳转第三方app的功能,需要用到原生app之间的跳转,类似微信和支付宝支付完可以回到自己的app,简单的说Scheme协议就是android中的一种页面内跳转协议,方便app页面的内的跳转

2. Scheme协议的格式

scheme 协议的名称 appcan
host 对应Schema作用于哪个地址域 freestyle
port 该协议路径的端口号 8080
path 代表Schema指定的页面以及参数 path?name=1994&time=10010

3.在工程中配置上面的协议

在AndroidManifest.xml中对应activity标签增加intent-filter设置Schema

 <activity android:name=".MainActivity">
        <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="appcan"
                    android:host="freestyle"
                    android:port="8080"
                    android:path="/path"
                    />
         </intent-filter>
  </activity>

注意下面的代码必须配置,而且scheme不能配置在程序的入口类中否则不起
作用

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

4.调用

Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse("appcan://freestyle:8080/path?name=1994&time=10010"));
startActivity(intent); 

相关文章

网友评论

      本文标题:Android 中Scheme协议的使用

      本文链接:https://www.haomeiwen.com/subject/lgzhkctx.html