I’m having trouble with Google authentication on my Android TV app. Here’s my current setup:
GoogleSignInOptions authOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.requestScopes(new Scope(DriveScopes.DRIVE_FILE), new Scope(DriveScopes.DRIVE_READONLY))
.build();
The authentication works fine initially on my TV device, but after a couple of days it stops working completely. To get it working again, I have to manually clear the Google Play Services cache and data, remove all accounts, and then sign in again. This temporary fix works but the same problem happens again after a few days.
What could be causing this recurring authentication failure? Is there a way to handle this programmatically instead of requiring manual intervention each time?
not totally sure, but maybe look into your oauth tokens? they tend to expire fast, so implementing a refresh token might help. also, keep an eye on that onConnectionFailed callback; super useful for auto re-auth when tokens go bad.
Had the same issue with Google APIs on Android TV. TV devices are way more aggressive than regular Android when it comes to clearing app data - they’ll wipe stuff when the device goes to sleep or sits idle too long.
Usually it’s the credential storage getting cleared during these cleanup cycles. What worked for me: check if your access token’s still valid before making API calls, then auto-trigger re-auth when needed instead of waiting for the call to fail. Also worth checking if your app has permissions to keep data during sleep cycles - some TV manufacturers are pretty strict about this.
Sounds like a credential caching issue with Android TV’s memory management. TV devices dump cached auth data way more aggressively than phones or tablets, especially after system updates or when memory runs low. I’ve hit this same problem before. Storing auth state in SharedPreferences instead of just relying on GoogleSignInAccount caching fixed the persistence issues for me. Try adding a token validation check in your app’s onCreate - have it quietly refresh credentials before hitting the Drive API. Also worth noting that Android TV devices get Google Play Services updates on different cycles, which can randomly kill your stored tokens. I started adding error handling that catches auth exceptions and automatically kicks off the sign-in flow again. Saves you from having to manually fix this every time.