Build a Hands-Free Selfie Android Application with MediaPipe
Introduction
Set up the Development Environment
Manage Camera Permissions
Integrate MediaPipe solutions
Manage UI state with ViewModel
Use SharedFlow to View Events
Use StateFlow to View Controller States
Mediate flows to trigger photo capture
Avoid duplicate photo capture requests
Next Steps
Build a Hands-Free Selfie Android Application with MediaPipe
Review frequently asked questions
These FAQs were drafted with an approved AI-assisted workflow and reviewed by Arm contributors before publication. Human technical review remains part of the process so the final page reflects engineering rigor, accuracy, and Arm editorial standards.
Add the version entry in
libs.versions.toml. After updating the catalog and syncing, Android Studio should resolve the MediaPipe artifacts so you can import the corresponding classes in your code.Enable USB debugging on the phone, then confirm the Allow USB debugging dialog by selecting Always allow from this computer and tapping the OK button. If you don’t see the dialog, review the Android Developer guidance for setting up a device for development.
Handle camera permissions immediately after connecting your device and before integrating AI features to avoid runtime blockers when accessing the camera with CameraX later.
Populate state through the
ViewModel class, then rotate the device or trigger a configuration change. The screen-level state should persist without refetching, indicating the ViewModel is working as intended.Use
SharedFlow for one-time UI events that multiple subscribers might observe. Use StateFlow for observable, current UI state that the View needs to render and react to over time.