bryantvu / TWA-Offline-Mode

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TWA Offline Mode

Table of Contents

Introduction

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.

Demo Flow

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.

Lifecycle Reconnect

  1. Airplane mode is enabled to simulate network disconnect.
  2. App seamlessly redirects from MainActivity to OfflineActivity.
  3. Airplane mode is disabled and network is reconnected.
  4. Navigate to homescreen and back into app.
  5. Placeholder splash screen appears before finally loading into TWA.
lifecycle.reconnect.mp4

Reconnect Button

  1. Airplane mode is enabled to simulate network disconnect.
  2. App seamlessly redirects from MainActivity to OfflineActivity.
  3. Airplane mode is disabled and network is reconnected.
  4. "Recheck Connection" button is clicked.
  5. Placeholder splash screen appears before finally loading into TWA.
reconnect.button.mp4

License

This Android sample code is licensed under the Apache License, version 2.0

Acknowledgements

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.

About

License:Apache License 2.0


Languages

Language:Java 100.0%