如何找到android应用程序深层链接的位置,就像在web中的开放引用中一样?

如何找到android应用程序深层链接的位置,就像在web中的开放引用中一样?,android,deep-linking,Android,Deep Linking,我需要找到我的应用程序开源的来源,比如(fb,twitter,g+)有办法找到它吗。 我知道url的标题中有一个开放的引用,但我如何在android应用程序中获取此信息呢 试试这个 在您的android清单文件上注册您的活动,该活动必须在单击链接时打开 <activity android:name=".YOURACTIVITY" android:label="@string/app_name" android:con

我需要找到我的应用程序开源的来源,比如(fb,twitter,g+)有办法找到它吗。
我知道url的标题中有一个开放的引用,但我如何在android应用程序中获取此信息呢 试试这个

在您的android清单文件上注册您的活动,该活动必须在单击链接时打开

 <activity
            android:name=".YOURACTIVITY"
            android:label="@string/app_name"
            android:configChanges="keyboardHidden|orientation|screenSize"
            android:screenOrientation="portrait">
            <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="http"
                    android:host="somedomainname.com"
                    android:pathPrefix="/index"/>

            </intent-filter>

        </activity>

谷歌为此提供在线材料:

摘要

您可以使用来获取深度链接的推荐人。它从API 22开始提供

对于API级别21及以下版本,您可以使用上述在线材料中的以下代码片段:

private static final String referer\u NAME=“android.intent.extra.referer\u NAME”;
/**返回运行SDK版本低于22的设备上的引用者*/
私有Uri getReferrerCompatible(活动){
Intent=activity.getIntent();
Uri refererUri=intent.getParcelableExtra(intent.EXTRA\u referer);
if(refererruri!=null){
返回refererri;
}
字符串referer=intent.getStringExtra(referer\u名称);
if(referer!=null){
//尝试分析引用者URL;如果无效,则返回null
试一试{
返回Uri.parse(referer);
}捕获(解析异常){
返回null;
}
}
返回null;
}

取决于@Ahmad Fadli answer(工作正常,但可能无法检测到某些应用程序) 我有一个类似的用例,因此可能有人需要它,您也可以同时使用它们:

fun getReferrerCompatible(activity: Activity?): String? {
    if (activity == null)
        return null
    try {
        val intent = activity.intent
        val bundle = intent.extras
        if (bundle != null) {
            val keySet = bundle.keySet().toTypedArray()
            for (k in keySet) {
                if (k.contains("application_id")) {
                    return bundle.getString(k)
                }

            }
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
            return activity.referrer?.toString()
        }
    } catch (e: Exception) {
        Crashlytics.logException(e)
    }
    return null
}

默认的
referer
实际上没有为chrome应用程序提供一些深度链接,出于某种原因,它会返回“google.com”

我使用的是“branch.io”,我需要知道用户的来源。@AbhishekSingh onInitFinished()具有包含源键“~channel”的jsonobject参数这已经回答了吗?下面的答案对我不起作用。
referer\u NAME
代表什么?谢谢,我添加了一个答案,不同的方法也有效,你的没有检测到一些chrome链接,但我将其用作备份plan@Ahmedna很高兴有选择。在我的例子中,返回“google.com”是预期的,因为用户点击谷歌网页内的链接,无论他是否从Chrome应用程序打开它。
fun getReferrerCompatible(activity: Activity?): String? {
    if (activity == null)
        return null
    try {
        val intent = activity.intent
        val bundle = intent.extras
        if (bundle != null) {
            val keySet = bundle.keySet().toTypedArray()
            for (k in keySet) {
                if (k.contains("application_id")) {
                    return bundle.getString(k)
                }

            }
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
            return activity.referrer?.toString()
        }
    } catch (e: Exception) {
        Crashlytics.logException(e)
    }
    return null
}