简单的说就是android中的一种页面内跳转协议,方便app页面的内的跳转
zymobi://3g2win:9999/macthDetail?macthId=222&time=10001
scheme | 代表该Schema 协议名称 | zymobi |
---|---|---|
host | 代表Schema作用于哪个地址域 | 3g2win |
port | 代表该路径的端口号 | 9999 |
path | 代表Schema指定的页面 | /macthDetail |
– | 代表传递的参数 | ?macthId=222&time=10001 |
在AndroidManifest.xml中对activity标签增加intent-filter设置Schema
<activity android:name=".SecondActivity">
<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="zymobi"
android:host="3g2win"
android:port="9999"
android:path="/macthDetail"
/>
intent-filter>
activity>
注意:
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
必须配置,scheme不能配置在程序的入口类中否则不起作用。
1.在html中调用非常简单
<a href="zymobi://3g2win:9999/macthDetail?macthId=222&time=10001">打开源生应用指定的页面a>
2.在源生应用中调用也很简单
Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse("zymobi://3g2win:9999/macthDetail?macthId=222&time=10001"));
startActivity(intent);
Intent intent = getIntent();
Uri data = intent.getData(); //
String action = intent.getAction();
String scheme = intent.getScheme();
Set<String> categories = intent.getCategories();
Log.e("TAG", "data==========="+data);
Log.e("TAG", "action==========="+action);
Log.e("TAG", "categories==========="+categories);
Log.e("TAG", "DataString==========="+intent.getDataString());
Log.e("TAG", "==============================");
Log.e("TAG", "scheme==========="+scheme);
Log.e("TAG", "id ==========="+data.getQueryParameterNames());
Log.e("TAG", "host==========="+data.getHost());
Log.e("TAG", "path==========="+data.getPath());
Log.e("TAG", "port==========="+data.getPort());
输出结果
4-11 18:13:56.335 5198-5198/com.phone.myapplication E/TAG: data===========zymobi://3g2win:9999/macthDetail?goodsId=10011002&time=1111
04-11 18:13:56.335 5198-5198/com.phone.myapplication E/TAG: action===========android.intent.action.VIEW
04-11 18:13:56.335 5198-5198/com.phone.myapplication E/TAG: categories===========null
04-11 18:13:56.335 5198-5198/com.phone.myapplication E/TAG: DataString===========zymobi://3g2win:9999/macthDetail?goodsId=10011002&time=1111
04-11 18:13:56.335 5198-5198/com.phone.myapplication E/TAG: ==============================
04-11 18:13:56.335 5198-5198/com.phone.myapplication E/TAG: scheme===========zymobi
04-11 18:13:56.335 5198-5198/com.phone.myapplication E/TAG: id ===========[goodsId, time]
04-11 18:13:56.335 5198-5198/com.phone.myapplication E/TAG: host===========3g2win
04-11 18:13:56.335 5198-5198/com.phone.myapplication E/TAG: path===========/macthDetail
04-11 18:13:56.335 5198-5198/com.phone.myapplication E/TAG: port===========9999
具体含义可以对比传入的参数
判断Schema是否有效,也可以说判断应用是否安装(在确定要启动的应用已经配置了scheme)
app源生判断Sheme是否有效
Intent intent = newIntent(Intent.ACTION_VIEW, Uri.parse("zymobi://3g2win:9999/macthDetail?macthId=222&time=10001"));
List activities =packageManager.queryIntentActivities(intent, 0);
boolean isValid = !activities.isEmpty();
Toast.makeText(this,isValid+"",Toast.LENGTH_LONG).show();
转自:https://blog.csdn.net/baidu_31956557/article/details/79900311