@@ -120,12 +120,14 @@ class MainActivity : ComponentActivity() {
120120 // MediaProjection
121121 private lateinit var mediaProjectionManager: MediaProjectionManager
122122 private lateinit var mediaProjectionLauncher: ActivityResultLauncher <Intent >
123+ private lateinit var webRtcMediaProjectionLauncher: ActivityResultLauncher <Intent >
123124
124125 private var currentScreenInfoForScreenshot: String? = null
125126
126127 private lateinit var navController: NavHostController
127128 private var isProcessingExplicitScreenshotRequest: Boolean = false
128129 private var onMediaProjectionPermissionGranted: (() -> Unit )? = null
130+ private var onWebRtcMediaProjectionResult: ((Int , Intent ) -> Unit )? = null
129131
130132 private val screenshotRequestHandler = object : BroadcastReceiver () {
131133 override fun onReceive (context : Context ? , intent : Intent ? ) {
@@ -187,15 +189,28 @@ class MainActivity : ComponentActivity() {
187189 // This should be guaranteed by its placement in onCreate.
188190 if (! ::mediaProjectionManager.isInitialized) {
189191 Log .e(TAG , " requestMediaProjectionPermission: mediaProjectionManager not initialized!" )
190- // Optionally, initialize it here as a fallback, though it indicates an issue with onCreate ordering
191- // mediaProjectionManager = getSystemService(Context.MEDIA_PROJECTION_SERVICE) as MediaProjectionManager
192- // Toast.makeText(this, "Error: Projection manager not ready. Please try again.", Toast.LENGTH_SHORT).show()
193192 return
194193 }
195194 val intent = mediaProjectionManager.createScreenCaptureIntent()
196195 mediaProjectionLauncher.launch(intent)
197196 }
198197
198+ /* *
199+ * Request a fresh MediaProjection permission specifically for WebRTC (Human Expert).
200+ * This does NOT start ScreenCaptureService - the result is passed directly to the callback.
201+ */
202+ fun requestMediaProjectionForWebRTC (onResult : (Int , Intent ) -> Unit ) {
203+ Log .d(TAG , " Requesting MediaProjection permission for WebRTC" )
204+ onWebRtcMediaProjectionResult = onResult
205+
206+ if (! ::mediaProjectionManager.isInitialized) {
207+ Log .e(TAG , " requestMediaProjectionForWebRTC: mediaProjectionManager not initialized!" )
208+ return
209+ }
210+ val intent = mediaProjectionManager.createScreenCaptureIntent()
211+ webRtcMediaProjectionLauncher.launch(intent)
212+ }
213+
199214 fun takeAdditionalScreenshot () {
200215 if (ScreenCaptureService .isRunning()) {
201216 Log .d(TAG , " MainActivity: Instructing ScreenCaptureService to take an additional screenshot." )
@@ -286,7 +301,7 @@ class MainActivity : ComponentActivity() {
286301
287302 when (currentTrialState) {
288303 TrialManager .TrialState .EXPIRED_INTERNET_TIME_CONFIRMED -> {
289- trialInfoMessage = " Your 30-minute trial period has ended. Please subscribe to the app to continue using it. "
304+ trialInfoMessage = " Please support the development of the app so that you can continue using it \uD83C\uDF89 "
290305 showTrialInfoDialog = true
291306 Log .d(TAG , " updateTrialState: Set message to \' $trialInfoMessage \' , showTrialInfoDialog = true (EXPIRED)" )
292307 }
@@ -444,6 +459,10 @@ class MainActivity : ComponentActivity() {
444459 if (result.resultCode == Activity .RESULT_OK && result.data != null ) {
445460 val shouldTakeScreenshotOnThisStart = this @MainActivity.isProcessingExplicitScreenshotRequest
446461 Log .i(TAG , " MediaProjection permission granted. Starting ScreenCaptureService. Explicit request: $shouldTakeScreenshotOnThisStart " )
462+
463+ // Notify ViewModel about the permission grant (for Human Expert WebRTC)
464+ photoReasoningViewModel?.onMediaProjectionPermissionGranted(result.resultCode, result.data!! )
465+
447466 val serviceIntent = Intent (this , ScreenCaptureService ::class .java).apply {
448467 action = ScreenCaptureService .ACTION_START_CAPTURE
449468 putExtra(ScreenCaptureService .EXTRA_RESULT_CODE , result.resultCode)
@@ -487,6 +506,21 @@ class MainActivity : ComponentActivity() {
487506 }
488507 }
489508
509+ // Separate WebRTC MediaProjection launcher - does NOT start ScreenCaptureService
510+ webRtcMediaProjectionLauncher = registerForActivityResult(
511+ ActivityResultContracts .StartActivityForResult ()
512+ ) { result ->
513+ if (result.resultCode == Activity .RESULT_OK && result.data != null ) {
514+ Log .i(TAG , " WebRTC MediaProjection permission granted." )
515+ onWebRtcMediaProjectionResult?.invoke(result.resultCode, result.data!! )
516+ onWebRtcMediaProjectionResult = null
517+ } else {
518+ Log .w(TAG , " WebRTC MediaProjection permission denied." )
519+ Toast .makeText(this , " Screen capture permission denied" , Toast .LENGTH_SHORT ).show()
520+ onWebRtcMediaProjectionResult = null
521+ }
522+ }
523+
490524 // Keyboard visibility listener
491525 val rootView = findViewById<View >(android.R .id.content)
492526 onGlobalLayoutListener = ViewTreeObserver .OnGlobalLayoutListener {
@@ -1222,7 +1256,7 @@ fun TrialExpiredDialog(
12221256 )
12231257 Spacer (modifier = Modifier .height(16 .dp))
12241258 Text (
1225- text = " Your 7-day trial period has ended. Please subscribe to the app to continue using it. " ,
1259+ text = " Please support the development of the app so that you can continue using it \uD83C\uDF89 " ,
12261260 style = MaterialTheme .typography.bodyMedium,
12271261 modifier = Modifier .align(Alignment .CenterHorizontally )
12281262 )
0 commit comments