Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

387
Views
Android, webview, inject Java/Kotlin code in Javascript

I have Javascript code (I removed most of the code)

var url = // some url;
__webpack_exports__["default"] = ({
  filters: {
        // some code
  },
  components: {
        // some components
  },
  data: function data() {
    return {
      // some data,
      phone: '',          
      // somde data  
    };
  },
  created: function created() {
     var _this2 = this;

    window.actions = {};

    window.actions.getPhoneNumber = function (number) {
      _this2.phone = number;
    };

    window.Android && (window.Android.getPhoneNumber = function (number) {
      _this2.phone = number;
    });
  },

And code in Android in fragment onCreated

@SuppressLint("SetJavaScriptEnabled")
    private fun configureViews() { 
            webview.webViewClient = TransfersWebViewClient(injectJs = { injectJavaScript() })
            webview.settings?.javaScriptEnabled = true
            webview.loadUrl(startUrl)
            }

Realize webview client

class TransfersWebViewClient(
       private val injectJs: (() -> Unit)? = null,
) : WebViewClient() {

    override fun onPageFinished(view: WebView?, url: String?) {
        super.onPageFinished(view, url)
        injectJs?.invoke()
    }
}

And the implementation of the injectJavaScript() function

private fun injectJavaScript() {
        webview.evaluateJavascript("actions.getPhoneNumber('33333');", null)
    }

i need to pass to javascript function window.actions.getPhoneNumber = function (number) { _this2.phone = number; }; my phone number, but I can't do it. Please tell me how to do this?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!