AndroidManifest.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"> <uses-permission android:name="android.permission.INTERNET" /> <application android:allowBackup="true" android:dataExtractionRules="@xml/data_extraction_rules" android:fullBackupContent="@xml/backup_rules" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.MyApplication" tools:targetApi="31"> <activity android:name=".MainActivity" android:exported="true" android:label="@string/app_name" android:theme="@style/Theme.MyApplication"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> |
activity_main.xml
1 2 3 4 5 6 7 8 9 10 11 12 |
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <WebView android:id="@+id/webView" android:layout_width="match_parent" android:layout_height="match_parent" /> </RelativeLayout> |
MainActivity.kt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
package com.example.myapplication import android.os.Bundle import android.os.SystemClock import android.view.MotionEvent import android.webkit.WebChromeClient import android.webkit.WebView import android.webkit.WebViewClient import androidx.activity.ComponentActivity class MainActivity : ComponentActivity() { private lateinit var webView: WebView private val url = "https://www.jesusninoc.com" // Reemplaza con la URL que desees mostrar override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) webView = findViewById(R.id.webView) webView.settings.javaScriptEnabled = true webView.webChromeClient = WebChromeClient() webView.webViewClient = object : WebViewClient() { override fun onPageFinished(view: WebView?, url: String?) { super.onPageFinished(view, url) simulateClickAtPosition(500, 500) } } webView.loadUrl(url) } private fun simulateClickAtPosition(x: Int, y: Int) { val downTime: Long = SystemClock.uptimeMillis() val eventTime: Long = SystemClock.uptimeMillis() + 100 val precision = 1.0f val motionEventDown = MotionEvent.obtain( downTime, eventTime, MotionEvent.ACTION_DOWN, x.toFloat(), y.toFloat(), precision.toInt() ) webView.dispatchTouchEvent(motionEventDown) val motionEventUp = MotionEvent.obtain( downTime, eventTime + 100, MotionEvent.ACTION_UP, x.toFloat(), y.toFloat(), precision.toInt() ) webView.dispatchTouchEvent(motionEventUp) } } |