forked from LinusU/flutter_web_auth
-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes Android when default browser is not support CustomTabs (#111)
* Fixes Android when default browser is not support CustomTabs * Fixes Android when default browser is not support CustomTabs * Update findTargetPackageName Priority: 1. Chrome 2. Custom Browser Order 3. default Browser 4. Installed Browser * Fix sometimes android:autoVerify="true" cannot works when it can't access Google after installation. * Remove CallbackActivity from RecentTask after finish. * Remove CallbackActivity from RecentTask after finish. * Refactor code. --------- Co-authored-by: kecson <kecson>
- Loading branch information
Showing
6 changed files
with
192 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.linusu.flutter_web_auth_2"> | ||
package="com.linusu.flutter_web_auth_2"> | ||
|
||
<queries> | ||
<intent> | ||
<action android:name="android.support.customtabs.action.CustomTabsService" /> | ||
</intent> | ||
</queries> | ||
</manifest> |
47 changes: 38 additions & 9 deletions
47
flutter_web_auth_2/android/src/main/kotlin/com/linusu/flutter_web_auth_2/CallbackActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,49 @@ | ||
package com.linusu.flutter_web_auth_2 | ||
|
||
import android.annotation.SuppressLint | ||
import android.app.Activity | ||
import android.content.Intent | ||
import android.net.Uri | ||
import android.os.Build | ||
import android.os.Bundle | ||
|
||
class CallbackActivity: Activity() { | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
class CallbackActivity : Activity() { | ||
|
||
val url = intent?.data | ||
val scheme = url?.scheme | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
if (scheme != null) { | ||
FlutterWebAuth2Plugin.callbacks.remove(scheme)?.success(url.toString()) | ||
val url = intent?.data ?: fixAutoVerifyNotWorks(intent) | ||
val scheme = url?.scheme | ||
|
||
if (scheme != null) { | ||
FlutterWebAuth2Plugin.callbacks.remove(scheme)?.success(url.toString()) | ||
} | ||
finishAndRemoveTask() | ||
} | ||
|
||
|
||
/** Fix sometimes android:autoVerify="true" cannot works when it can't access Google after installation. | ||
* See https://stackoverflow.com/questions/76383106/auto-verify-not-always-working-in-app-links-using-android | ||
* | ||
* must register in AndroidManifest.xml : | ||
* <intent-filter> | ||
* <action android:name="android.intent.action.SEND" /> | ||
* <category android:name="android.intent.category.DEFAULT" /> | ||
* <data android:mimeType="text/plain" /> | ||
*</intent-filter> | ||
*/ | ||
private fun fixAutoVerifyNotWorks(intent: Intent?): Uri? { | ||
if (intent?.action == Intent.ACTION_SEND && "text/plain" == intent.type) { | ||
return intent.getStringExtra(Intent.EXTRA_TEXT)?.let { | ||
try { | ||
//scheme://host/path#id_token=xxx | ||
return Uri.parse(it) | ||
} catch (e: Exception) { | ||
return null | ||
} | ||
} | ||
} | ||
return null | ||
} | ||
|
||
finish() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters