How FadCam Handles Permissions for Background Recording and Streaming
FadCam handles permissions for background recording and streaming by declaring specialized foreground service types in AndroidManifest.xml and using a transparent activity (TransparentPermissionActivity) to request runtime permissions before launching services like RecordingService or RemoteStreamService.
FadCam implements Android’s modern permission model to enable continuous camera, microphone, and screen capture while the app runs in the background. The permission architecture centers on three components: manifest declarations for specialized foreground services, a transparent permission activity for runtime consent, and strict service-to-permission mapping that ensures compliance with Android 10+ background execution limits.
Manifest Permission Declarations
All required permissions are declared in app/src/main/AndroidManifest.xml, establishing the foundation for background recording capabilities. FadCam requests standard runtime permissions alongside specialized foreground service permissions introduced in recent Android versions.
CAMERA(line 48): Grants access to device cameras for video capture.RECORD_AUDIO(line 65): Enables microphone access for audio track recording.FOREGROUND_SERVICE(line 69): Base permission allowing the app to start foreground services.FOREGROUND_SERVICE_CAMERA(line 73): Required forRecordingServiceandDualCameraRecordingServiceto access the camera while backgrounded.FOREGROUND_SERVICE_MICROPHONE(line 75): Allows background audio capture through foreground services.FOREGROUND_SERVICE_DATA_SYNC(line 76): EnablesRemoteStreamServiceto stream data over the network while in the background.FOREGROUND_SERVICE_MEDIA_PROJECTION(line 74): Required forScreenRecordingServiceto capture screen content.FOREGROUND_SERVICE_SPECIAL_USE(line 54): Permits theAnnotationServiceoverlay functionality.
These declarations inform the Android system that the app may request these permissions at runtime, but actual access is gated through the transparent permission activity.
Foreground Service Registration
Each background recording component is registered as a foreground service with specific android:foregroundServiceType attributes that map directly to the permissions they require. This declaration tells Android which runtime permissions must be granted before the service can start.
| Service | Manifest Line | Foreground Service Type |
|---|---|---|
RecordingService |
86 | camera|microphone |
DualCameraRecordingService |
88 | camera|microphone |
RemoteStreamService |
92 | dataSync |
ScreenRecordingService |
95 | mediaProjection|microphone |
AnnotationService |
101 | specialUse |
When ContextCompat.startForegroundService() is called, Android verifies that the user has granted the corresponding runtime permissions matching the service type. If permissions are missing, the service start fails immediately.
Runtime Permission Flow
Because Android 6.0+ requires dynamic permission grants, FadCam uses a specialized transparent activity pattern to request consent without disrupting the user experience or bringing the main app to the foreground.
TransparentPermissionActivity
The TransparentPermissionActivity (declared in the manifest at lines 74-81) is a translucent, no-UI component that handles permission requests. It uses the theme @android:style/Theme.Translucent.NoTitleBar with android:noHistory="true" to remain invisible and remove itself from the back stack immediately after execution.
When a user initiates background recording, the app launches this activity, which calls ActivityCompat.requestPermissions() for the required permissions:
// TransparentPermissionActivity.kt (simplified)
class TransparentPermissionActivity : AppCompatActivity() {
private val REQUEST_CODE = 1001
private val REQUIRED_PERMISSIONS = arrayOf(
Manifest.permission.CAMERA,
Manifest.permission.RECORD_AUDIO
)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// Request all needed permissions in one go
ActivityCompat.requestPermissions(this, REQUIRED_PERMISSIONS, REQUEST_CODE)
}
override fun onRequestPermissionsResult(
requestCode: Int, permissions: Array<String>, grantResults: IntArray
) {
if (requestCode == REQUEST_CODE && grantResults.all { it == PackageManager.PERMISSION_GRANTED }) {
// Permissions OK – start the background service
startService(Intent(this, RecordingService::class.java))
} else {
// Show rationale / fallback UI
Toast.makeText(this, "Permissions required for recording", Toast.LENGTH_LONG).show()
}
finish() // close the transparent activity
}
}
Service Launch Sequence
Once permissions are granted, the transparent activity starts the appropriate foreground service via explicit Intent. For streaming functionality, the app uses RecordingStartActivity (also transparent) to initiate RemoteStreamService:
// Starting a foreground service (e.g. RemoteStreamService)
fun startStreaming(context: Context) {
val intent = Intent(context, RemoteStreamService::class.java).apply {
action = RemoteStreamService.ACTION_START
}
ContextCompat.startForegroundService(context, intent)
}
The service then promotes itself to foreground status with a persistent notification, allowing it to continue operating even when the user switches to other apps:
// RemoteStreamService.kt (simplified)
@AndroidEntryPoint
class RemoteStreamService : Service() {
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
// The system guarantees we have the DATA_SYNC permission because
// the manifest declares android:foregroundServiceType="dataSync"
startForeground(NOTIFICATION_ID, buildNotification())
// Start streaming logic here …
return START_STICKY
}
}
Permission Denial Handling
If the user denies any permission in onRequestPermissionsResult, FadCam displays a user-friendly Toast explaining why the permission is required for background recording, then finishes the transparent activity without starting the service. The app does not crash or force-close; it simply prevents the recording operation from initiating.
Key Implementation Files
app/src/main/AndroidManifest.xml: Declares all runtime permissions and foreground service types with their specificforegroundServiceTypeattributes.TransparentPermissionActivity: Handles runtime permission requests for camera and microphone without visible UI.RecordingStartActivity/RecordingStopActivity: Translucent activities that bridge user actions to service lifecycle management.RecordingService: Foreground service for standard camera recording (type:camera|microphone).DualCameraRecordingService: Handles picture-in-picture dual camera recording (type:camera|microphone).RemoteStreamService: Provides LAN HTTP streaming capabilities (type:dataSync).ScreenRecordingService: Captures device screen content using MediaProjection (type:mediaProjection|microphone).
Summary
- FadCam declares specialized foreground service permissions in
AndroidManifest.xmlto comply with Android 10+ background execution policies. - The
TransparentPermissionActivityrequests runtime permissions without displaying a visible interface, ensuring smooth background recording initiation. - Each service (
RecordingService,RemoteStreamService, etc.) declares specificforegroundServiceTypeattributes that Android enforces at runtime. - Permission grants are verified before service starts; if denied, the app shows explanatory messaging rather than crashing.
- The architecture separates permission handling (transparent activities) from recording logic (foreground services), maintaining clean separation of concerns.
Frequently Asked Questions
What permissions are required for FadCam to record in the background?
FadCam requires CAMERA and RECORD_AUDIO for basic functionality, plus FOREGROUND_SERVICE_CAMERA, FOREGROUND_SERVICE_MICROPHONE, and FOREGROUND_SERVICE_DATA_SYNC to run services in the background. Screen recording additionally requires FOREGROUND_SERVICE_MEDIA_PROJECTION. All permissions are declared in app/src/main/AndroidManifest.xml and requested at runtime through TransparentPermissionActivity.
How does FadCam request permissions without showing a visible app window?
FadCam uses TransparentPermissionActivity, which is configured with Theme.Translucent.NoTitleBar and noHistory="true". This activity calls ActivityCompat.requestPermissions() immediately upon creation, presenting the system permission dialog while remaining invisible itself. Once the user responds, the activity finishes automatically, leaving no trace in the recent apps list.
Why does FadCam use different foreground service types for different features?
Android requires specific foregroundServiceType declarations to enforce privacy policies for background operations. Camera recording uses camera|microphone, streaming uses dataSync, and screen recording uses mediaProjection|microphone. These types ensure that only services with matching runtime permissions can start, preventing unauthorized background access to sensitive hardware.
What happens if I deny a permission when starting a recording?
If permissions are denied in onRequestPermissionsResult, FadCam displays a Toast message explaining that the permission is required for recording, then closes the transparent activity without starting the foreground service. The recording operation is cancelled gracefully, and the app returns to its previous state without crashing or forcing a closure.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →