The purpose of this Android project is to provide an example of how a TWA app can to redirect to a placeholder activity when the device is not connected to the internet on app start up.
The network connectivity is queried using the Android ConnectivityManger. The user can manually check the network connectivity and attempt to reload the TWA using a button on the OfflineActivity. Additionally, the app will automatically check by itself based on the activity lifecycle if the user navigates out and back.
Please use 'TwaOfflineFeature.apk' if you just want to test the demo out. Note that the TWA is launched using the Huawei Browser which does not support hiding the navigation bar at the top.
- Airplane mode is enabled to simulate network disconnect.
- App seamlessly redirects from MainActivity to OfflineActivity.
- Airplane mode is disabled and network is reconnected.
- Navigate to homescreen and back into app.
- Placeholder splash screen appears before finally loading into TWA.
lifecycle.reconnect.mp4
- Airplane mode is enabled to simulate network disconnect.
- App seamlessly redirects from MainActivity to OfflineActivity.
- Airplane mode is disabled and network is reconnected.
- "Recheck Connection" button is clicked.
- Placeholder splash screen appears before finally loading into TWA.
reconnect.button.mp4
This Android sample code is licensed under the Apache License, version 2.0
The code in this project is built on the foundation provided by Trusted Web Activities (Android Browser Helper). Their work in making this possible is greatly appreciated.