未调用Android onNewIntent

时间:2019-07-16 08:21:10

标签: android redirect android-intent oauth chrome-custom-tabs

我正在与Google Android/Kotlin一起Chrome Custom Tab工作,CCT正在为第三方服务器做oAuth。 oAuth完成后,CCT应该重定向到我的redirect_url,在这里我正在onNewIntentonCreate中捕获它。不幸的是,我的redirect_url并未被要求进行首次启动。但是当我第二次重新启动它时,它会被调用。可能是什么原因?

我的AndroidManifests.xml:

<activity android:name=".activities.MainActivity"
        android:exported="true"
        android:launchMode="singleTop">

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

        <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="test"
                android:host="apps.test.abc.com" />
        </intent-filter>
    </activity>

我的MainActivity.kt:

class MainActivity : BaseActivity() {

    override fun onNewIntent(intent: Intent?) {
        super.onNewIntent(intent)
        Logger.v(classTag, "onNewIntent")
    }

    override fun onCreate(onCreate: Bundle?)
        super.onCreate(onCreate)
        Logger.v(classTag, "onCreate")
    }
}

我打给CCT的电话

val builder = CustomTabsIntent.Builder()
val cctIntent = builder.build()
cctIntent.intent.flags = Intent.FLAG_ACTIVITY_NO_HISTORY
cctIntent.intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
cctIntent.launchUrl(mContext, Uri.parse(3RD_PARTY_OAUTH_URL))

oAuth完成后,当我第一次使用CCT启动3RD_PARTY_OAUTH_URL时,它不会调用test://apps.test.abc.com,但是当我第二次调用它时,它调用test://apps.test.abc.com可能是从缓存中获取的或Cookie。我的本地问题有没有机会,或者可能是第三方服务器方面的错?

请注意,对于有效的redirect_url,网络浏览器在初次尝试时效果很好。

0 个答案:

没有答案
相关问题