美文网首页
Android 利用scheme协议进行跳转

Android 利用scheme协议进行跳转

作者: Dazzzzzzzzzzzz | 来源:发表于2020-09-09 15:35 被阅读0次

干货!

从其他APP跳转到自家APP,从APP中接入的三方公司的SDK跳转的自己写的页面,都可以用到这个方法!

第一步,在AndroidManifest.xml中,activity标签下:

<!--Scheme跳转-->

<activity android:name=".activity.SchemeActivity"

    android:windowSoftInputMode="stateHidden|adjustPan"

    android:screenOrientation="portrait">

    <!-- 要想在别的App上能成功调起App,必须添加intent过滤器 -->

    <!-- 协议部分,随便设置 -->

        <!--协议部分,随便设置-->

        <data android:scheme="suibianxie" android:host="xls" android:path="/path" />

        <!--下面这几行也必须得设置-->

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

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

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

</activity>

第二步,在需要发起跳转的地方:

String url = "suibianxie://xls/path?path=10086";

Intent intent = new Intent(Intent.ACTION_VIEW,

Uri.parse(url));

startActivity(intent);

第三部,在需要打开的目标页面:

Uri data = getIntent().getData();

//        Log.i(TAG, "host = " + data.getHost() + " path = " + data.getPath() + " query = " + data.getQuery());

String param = data.getQueryParameter("path");

获取到需要的数据(10086)

可以通过获取到的10086,继续进行操作:

switch (param){

    case "10086":

    // 需要执行的代码

    break;

}

相关文章

网友评论

      本文标题:Android 利用scheme协议进行跳转

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