Android 8 App restart after redirection
I have successfully implemented flutter_web_auth on flutter android app.
It work very well with an android 9 smartphone, but on an android 8 Huawei Mediapad T5 i experience problems.
At debug time, when Chrome browser is launching i got an error "Lost connection to device." and flutter run hang.
Once login page appear, if i authenticate, redirection is done to application, but then i can see appliaction restarting (I see splash screen again) and token is not saved. I think Application hang and restart before token saving, but as i have lost console informations due to flutter hang i can't debug what happenned.
My authenticate function:
authenticate() async {
final result = await FlutterWebAuth.authenticate(
url: "https://xxx.xxx.eu/auth/login?authorize=yes",
callbackUrlScheme: "com.example.xxxx");
final token = Uri.parse(result).queryParameters['token'] ?? '';
var prefs = await SharedPreferences.getInstance();
prefs.setString("token", token);
refreshAfterAuthentication();
}
AndroidManifest.xml:
<activity android:name="com.linusu.flutter_web_auth.CallbackActivity" >
<intent-filter android:label="flutter_web_auth">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="com.example.xxxx" />
</intent-filter>
</activity>
Web redirection after authentication (Angular app) :
window.location.href = 'com.example.zzzz://success?token=' + data.token;
Flutter doctor:
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.0.2, on macOS 12.3.1 21E258 darwin-x64, locale fr-FR)
[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 13.4.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.1)
[✓] VS Code (version 1.68.0)
[✓] Connected device (5 available)
[✓] HTTP Host Availability
As it work well with my Android 9 smartphone, is it possible there is an issue with Androi 8 tablet ?
I solved this issue by adding an exported attibute to activity in AndroidManifest.xml, like this :
AndroidManifest.xml:
<activity android:name="com.linusu.flutter_web_auth.CallbackActivity" android:exported="true">
<intent-filter android:label="flutter_web_auth">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="com.example.andidoor" />
</intent-filter>
</activity>
Android Documentation: https://developer.android.com/guide/topics/manifest/activity-element#exported
android:exported="true"
This has been added to the installation and troubleshooting guide, will cut a new release shortly 👍