通过意图打开活动时的getReferrer返回null

时间:2018-10-18 09:50:34

标签: android android-intent referrer

我在清单中有一项旨在达到此目的的活动:

<activity
    android:name=".view.MainActivity"
    android:launchMode="singleTask"
    android:screenOrientation="portrait">
    <intent-filter>
        <data android:scheme="http" android:host="mc8.eu"/>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.BROWSABLE"/>
        <category android:name="android.intent.category.DEFAULT"/>
    </intent-filter>
</activity>

如果使用此方案接收SMS,则单击URL即可正确打开活动。

我需要了解该活动是由意图还是由另一个应用程序活动打开的。

我尝试了以下代码:

@Override
protected void onResume() {
    super.onResume();

    Uri ref = getReferrer();
}

但是getReferrer始终返回null。

1 个答案:

答案 0 :(得分:0)

一旦系统通过意图过滤器开始活动,您就可以使用意图提供的数据来确定需要呈现的内容。调用getData()和getAction()方法以检索与传入的Intent关联的数据和操作

    @Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Intent intent = getIntent();
    String action = intent.getAction();
    Uri data = intent.getData();
}

Android Documentation

相关问题