【问题标题】:getReferrer when activity is opened by a intent returns null当意图打开活动时,getReferrer 返回 null
【发布时间】:2018-10-18 09:50:33
【问题描述】:

我在清单中有一个具有此意图的活动:

<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>

如果我收到带有此方案的短信,如果我点击 url,活动就会正确打开。

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

我尝试使用此代码:

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

    Uri ref = getReferrer();
}

但是 getReferrer 总是返回 null。

【问题讨论】:

    标签: android android-intent referrer


    【解决方案1】:

    一旦系统通过 Intent 过滤器启动您的 Activity,您就可以使用 Intent 提供的数据来确定您需要渲染的内容。调用 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

    【讨论】:

    猜你喜欢
    • 2017-10-15
    • 1970-01-01
    • 1970-01-01
    • 2020-09-20
    • 1970-01-01
    • 2018-10-31
    • 2015-11-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多