Integration Checklist
Use this checklist to ensure your LiteP2P Android integration is complete and follows all best practices.
Final Rule
LiteP2P must cooperate with Android, not fight it. Following this checklist ensures your app works with Android's power management for the best user experience.
Required Items
These items are mandatory for a working integration:
Push notifications implemented – FCM or UnifiedPush configured and tested
FSM-driven peer state – Using LiteP2P's state machine for message gating
Message gating enforced – Only sending messages in appropriate states
Foreground Service for active work – File transfers and syncs use foreground service
Battery optimization exemption – User prompted to disable battery optimization
Manifest Configuration
<manifest>
<!-- Required permissions -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<application>
<!-- Foreground service -->
<service
android:name=".LiteP2PService"
android:foregroundServiceType="dataSync"
android:exported="false" />
<!-- FCM Service -->
<service
android:name=".LiteP2PMessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<!-- Boot receiver (optional) -->
<receiver
android:name=".BootReceiver"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
</manifest>
Initialization Code
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
// Initialize LiteP2P
val config = PeerConfig.Builder()
.setAppId("your-app-id")
.enableEncryption(true)
.setPushProvider(PushProvider.FCM)
.setKeepalivePolicy(KeepalivePolicy.ADAPTIVE)
.build()
LiteP2P.initialize(this, config)
// Register FCM token
FirebaseMessaging.getInstance().token.addOnSuccessListener { token ->
LiteP2P.getInstance().registerPushToken(token)
}
}
}
Runtime Checks
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// Check battery optimization
if (!LiteP2P.isBatteryOptimizationDisabled(this)) {
showBatteryOptimizationDialog()
}
// Check OEM-specific settings
if (LiteP2P.needsOEMConfiguration(this)) {
LiteP2P.showOEMConfigurationGuide(this)
}
// Request notification permission (Android 13+)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
requestNotificationPermission()
}
}
private fun showBatteryOptimizationDialog() {
AlertDialog.Builder(this)
.setTitle("Enable Background Sync")
.setMessage("For reliable P2P connectivity, please allow this app to run in the background.")
.setPositiveButton("Enable") { _, _ ->
LiteP2P.requestBatteryOptimizationExemption(this)
}
.setNegativeButton("Later", null)
.show()
}
}
Testing Checklist
App receives push notifications when killed
App wakes and syncs from push notification
File transfers complete when app is in background
App survives 1+ hour in background
App works after device reboot
Tested on Xiaomi device
Tested on Samsung device
Tested with battery saver enabled
Battery impact measured and acceptable
Common Issues
| Issue | Likely Cause | Solution |
|---|---|---|
| App killed in background | Battery optimization enabled | Request exemption |
| Push not received | Token not registered | Check FCM registration |
| Connections drop | No foreground service | Use foreground service for active work |
| Works on Pixel, fails on Xiaomi | OEM restrictions | Guide user to OEM settings |
| High battery usage | Wrong keepalive policy | Use ADAPTIVE policy |
Validation Tool
Use LiteP2P's built-in validation:
// Run validation check
val validation = LiteP2P.validateIntegration(context)
if (!validation.isComplete) {
validation.issues.forEach { issue ->
Log.w("LiteP2P", "Integration issue: ${issue.description}")
Log.w("LiteP2P", "Fix: ${issue.solution}")
}
}
// Output example:
// Integration issue: Battery optimization not disabled
// Fix: Call LiteP2P.requestBatteryOptimizationExemption()
//
// Integration issue: Push token not registered
// Fix: Register FCM token with LiteP2P.registerPushToken()
Need Help?
If you're experiencing issues after completing this checklist, check our Troubleshooting Guide or reach out on Discord.