@@ -518,7 +518,18 @@ class MainActivity : ComponentActivity() {
518518 ActivityResultContracts .StartActivityForResult ()
519519 ) { result ->
520520 if (result.resultCode == Activity .RESULT_OK && result.data != null ) {
521- Log .i(TAG , " WebRTC MediaProjection permission granted." )
521+ Log .i(TAG , " WebRTC MediaProjection permission granted. Starting keep-alive service." )
522+
523+ // Task 4: Keep Service Alive to satisfy Android 14 MediaProjection requirements
524+ val serviceIntent = Intent (this , ScreenCaptureService ::class .java).apply {
525+ action = ScreenCaptureService .ACTION_KEEP_ALIVE_FOR_WEBRTC
526+ }
527+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .O ) {
528+ startForegroundService(serviceIntent)
529+ } else {
530+ startService(serviceIntent)
531+ }
532+
522533 onWebRtcMediaProjectionResult?.invoke(result.resultCode, result.data!! )
523534 onWebRtcMediaProjectionResult = null
524535 } else {
@@ -654,7 +665,22 @@ class MainActivity : ComponentActivity() {
654665 Button (
655666 onClick = {
656667 showPaymentMethodDialog = false
657- showPayPalWebViewDialog = true
668+
669+ // Generate Short UUID
670+ val shortId = java.util.UUID .randomUUID().toString().substring(0 , 8 )
671+
672+ // Save it to SharedPreferences
673+ val ctx = this @MainActivity
674+ ctx.getSharedPreferences(PREFS_NAME , Context .MODE_PRIVATE )
675+ .edit()
676+ .putString(" payment_support_id" , shortId)
677+ .apply ()
678+
679+ Toast .makeText(ctx, " Your Support ID is: $shortId " , Toast .LENGTH_LONG ).show()
680+
681+ val url = " https://www.paypal.com/webapps/billing/subscriptions?plan_id=P-5J921557TD348880GNGUCRSI&custom_id=$shortId "
682+ val intent = Intent (Intent .ACTION_VIEW , android.net.Uri .parse(url))
683+ ctx.startActivity(intent)
658684 },
659685 modifier = Modifier .fillMaxWidth().padding(bottom = 8 .dp)
660686 ) {
@@ -680,82 +706,7 @@ class MainActivity : ComponentActivity() {
680706 )
681707 }
682708
683- // Task 6: PayPal WebView Dialog
684- if (showPayPalWebViewDialog) {
685- Dialog (
686- onDismissRequest = { showPayPalWebViewDialog = false },
687- properties = DialogProperties (usePlatformDefaultWidth = false )
688- ) {
689- Card (modifier = Modifier .fillMaxSize().padding(16 .dp)) {
690- Column (modifier = Modifier .fillMaxSize()) {
691- Row (
692- modifier = Modifier .fillMaxWidth().padding(8 .dp),
693- horizontalArrangement = Arrangement .SpaceBetween ,
694- verticalAlignment = Alignment .CenterVertically
695- ) {
696- Text (" PayPal Subscription" , style = MaterialTheme .typography.titleMedium)
697- TextButton (onClick = { showPayPalWebViewDialog = false }) {
698- Text (" Close" )
699- }
700- }
701-
702- androidx.compose.ui.viewinterop.AndroidView (
703- factory = { ctx ->
704- android.webkit.WebView (ctx).apply {
705- settings.javaScriptEnabled = true
706- settings.domStorageEnabled = true
707- webViewClient = android.webkit.WebViewClient ()
708-
709- // Generate Short UUID
710- val shortId = java.util.UUID .randomUUID().toString().substring(0 , 8 )
711-
712- // Save it to SharedPreferences
713- ctx.getSharedPreferences(PREFS_NAME , Context .MODE_PRIVATE )
714- .edit()
715- .putString(" payment_support_id" , shortId)
716- .apply ()
717-
718- val html = """
719- <!DOCTYPE html>
720- <html>
721- <head>
722- <meta name="viewport" content="width=device-width, initial-scale=1">
723- </head>
724- <body>
725- <div id="paypal-button-container-P-5J921557TD348880GNGUCRSI"></div>
726- <script src="https://www.paypal.com/sdk/js?client-id=AQ52P9G85S3RCHw7lWnEDH_Pudk-5JdE8S6gBfS72jWwMng-xR-0qNrtmS8Mv5RtdK--a1cZ0G-12_rZ&vault=true&intent=subscription" data-sdk-integration-source="button-factory"></script>
727- <script>
728- paypal.Buttons({
729- style: {
730- shape: 'rect',
731- color: 'gold',
732- layout: 'vertical',
733- label: 'subscribe'
734- },
735- createSubscription: function(data, actions) {
736- return actions.subscription.create({
737- 'plan_id': 'P-5J921557TD348880GNGUCRSI',
738- 'custom_id': '$shortId '
739- });
740- },
741- onApprove: function(data, actions) {
742- alert('Thank you for your subscription! Your Support ID is: $shortId ');
743- }
744- }).render('#paypal-button-container-P-5J921557TD348880GNGUCRSI');
745- </script>
746- </body>
747- </html>
748- """ .trimIndent()
749-
750- loadDataWithBaseURL(" https://www.paypal.com" , html, " text/html" , " UTF-8" , null )
751- }
752- },
753- modifier = Modifier .fillMaxSize()
754- )
755- }
756- }
757- }
758- }
709+
759710 }
760711 }
761712 }
0 commit comments