cd ZENITH-Frontend
flutter clean
flutter pub get
flutter run # or flutter build apk- Grant Health Connect permissions (Steps & Distance)
- Grant Location permissions (While using app OR Always)
- Accept Battery Optimization exemption dialog
- Walk around to generate steps
- Open app → Leaderboard
- Tap menu (⋮) → "Force Sync Steps"
- Should see: "Starting manual step sync..." toast
- Wait 2-3 seconds
- Should see: "Step sync completed!" toast
- Numbers should update
# Start monitoring
adb logcat -c
adb logcat | Select-String -Pattern "StepSync|BackgroundSync|BatteryOpt"# Is app installed?
adb shell pm list packages | Select-String "zenith"
# Battery optimization status
adb shell dumpsys deviceidle whitelist | Select-String "zenith"
# Check background tasks
adb shell dumpsys alarm | Select-String "com.example.zenith"# Clear logs first
adb logcat -c
# Watch for sync activity
adb logcat | Select-String "StepSync"| Issue | Check | Fix |
|---|---|---|
| No sync at all | Battery optimization | Settings → Apps → ZENITH → Battery → Unrestricted |
| Permission errors | Health Connect | Settings → Health Connect → ZENITH → Grant all |
| Location errors | Location permission | Settings → Apps → ZENITH → Permissions → Location → Always |
| Backend errors | Auth token | Re-login to app |
| No steps recorded | Walking | Actually walk around! |
- Frequency: Every 15 minutes
- Trigger: WorkManager (Android)
- Requirements: Network + Battery not low
- Logs: Check for
[StepSync]entries
- Trigger: Leaderboard menu → "Force Sync Steps"
- Immediate: Runs right away
- Feedback: Toast messages
- Refresh: Auto-refreshes leaderboard after 2 seconds
✅ Logs show:
[StepSync] >>> Step sync invoked with ID: ...
[StepSync] Health Connect permission: true
[StepSync] Fetched delta: steps=150, distance=0.1125
[StepSync] Location: 28.6139, 77.2090
[StepSync] Backend response: total_points=1268.3
[StepSync] ✅ Sync successful!
✅ Leaderboard updates:
- Points increase
- Distance increases
- Rank changes (if applicable)
✅ Backend receives:
{
"distance_delta_km": 0.1125,
"steps_delta": 150,
"latitude": 28.6139,
"longitude": 77.2090,
"sync_source": "health_connect",
"sync_id": "uuid-here"
}- ✅ AndroidManifest.xml - Permissions
- ✅ MainActivity.kt - Battery optimization
- ✅ battery_optimization_service.dart - NEW
- ✅ background_sync_service.dart - Enhanced
- ✅ leaderboard_screen.dart - Manual sync
- ✅ main.dart - Init battery opt
# Full test sequence
.\test_sync.bat
# Quick log check
adb logcat | Select-String "StepSync" | Select-Object -Last 20
# Force kill and restart background workers
adb shell am force-stop com.example.zenith
adb shell am start -n com.example.zenith/.MainActivity[StepSync] ✅ Sync successful!
[BackgroundSync] Step sync completed
[StepSync] No auth token, skipping sync
Fix: Re-login
[StepSync] Health Connect permission: false
Fix: Grant Health Connect permissions
[StepSync] Location permission: LocationPermission.denied
Fix: Grant location permission
[StepSync] ❌ Failed: BackendException
Fix: Check backend server status, network, auth token
💡 Use manual sync for immediate testing - Don't wait 15 minutes!
💡 Check logs BEFORE complaining - They tell you exactly what's wrong
💡 Walk at least 50+ steps - Small movements may not register
💡 Ensure device not in Doze mode - Charge device or keep screen on
💡 Network must be available - Background sync requires connectivity
- Check LEADERBOARD_SYNC_FIX.md - Full detailed documentation
- Run test_sync.bat - Automated testing script
- Monitor logs -
adb logcat | Select-String "StepSync" - Test in Postman - Verify backend is actually working
Last Updated: December 29, 2025 Status: ✅ Ready for testing