Android 隐士跳转几种方式

1、只有 配置 action 进行跳转

<intent-filter>
    <action android:name="testarouter"></action>
    <category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Intent intent = new Intent();
intent.setAction("testarouter");
startActivity(intent);

2、只附带 category 跳转

<intent-filter>
    <action android:name="testarouter"></action>
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.INFO" />
</intent-filter>
Intent intent = new Intent();
intent.setAction("testarouter");
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.addCategory(Intent.CATEGORY_INFO);
startActivity(intent);

3、只附带 data 跳转

//注:setData、setDataAndType、setType 这三种方法只能单独使用,不可共用
3.1、
<intent-filter>
    <action android:name="testarouter"></action>
    <category android:name="android.intent.category.DEFAULT" />
    <data
        android:path="/testrpouter"
        android:scheme="x1"
        tools:ignore="AppLinkUrlError" />
</intent-filter>

Intent intent = new Intent();
intent.setAction("testarouter");
Uri uri = Uri.parse("x1:/testarouter");
intent.setData(uri);
startActivity(intent);

3.2、
<intent-filter>
    <action android:name="testarouter"></action>
    <category android:name="android.intent.category.DEFAULT" />
    <data
        android:path="/testarouter"
        android:scheme="x1"
        android:mimeType="text/plain"
        tools:ignore="AppLinkUrlError" />
</intent-filter>

Intent intent = new Intent();
intent.setAction("testarouter");
Uri uri = Uri.parse("x1:/testarouter");
intent.setDataAndType(uri, "text/plain");
startActivity(intent);

3.3、
<intent-filter>
    <action android:name="testarouter"></action>
    <category android:name="android.intent.category.DEFAULT" />
    <data
        android:mimeType="text/plain"
        tools:ignore="AppLinkUrlError" />
</intent-filter>

Intent intent = new Intent();
intent.setAction("testarouter");
intent.setType("text/plain");
startActivity(intent);

猜你喜欢

转载自blog.csdn.net/zisetiankong123/article/details/82849464