我怎么知道我的应用是由Google Assistant打开的,而不是正常启动的。 我不需要应用程序操作。我只想知道,是的,我的应用程序是用“确定Google->打开应用程序名称”打开的,而不是按该图标或从最近的图标恢复它。 如果捆绑包中有意图/任何数据,我可以检查一下?
这是我执行“打开应用程序名称”的意图
Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 pkg=com.xelion.android cmp=com.xelion.android/.activity.Initializationactivity (has extras) }
它还有其他功能,但不知道是什么:
Bundle[mParcelledData.dataSize=220]
编辑:
我发现这将是使用Google Assistant打开的标志:
intent.flags == 0x10000000
但是我的问题是,当我从机器上构建应用程序或更新应用程序时,它也将运行。您知道如何避免这种情况吗?
EDIT2:
我也尝试过:
private fun getReferrerCompatible(activity: activity): Uri? {
val intent = activity.intent
val referrerUri: Uri? = intent.getParcelableExtra(Intent.EXTRA_REFERRER)
if (referrerUri != null) {
return referrerUri
}
val referrer = intent.getStringExtra(REFERRER_NAME)
if (referrer != null) {
// Try parsing the referrer URL; if it's invalid,return null
try {
return Uri.parse(referrer)
} catch (e: ParseException) {
return null
}
}
return null
}
但是我仍然作为引荐来源网址为
我正在尝试onCreate上的intent.extras?.get(KEY_REF_NAME) == REG_G_ASSISTANT
或getReferrerCompatible()
。应该晚一点吗?喜欢onResume吗?