you could implement a JavascriptInterface on Android.
look at this answer.
https://es.stackoverflow.com/questions/127574/javascript-interface-android-webview-call-java-function-from-js-onclick
based on this, you could make some code like below:
JavaScriptInterface jsInterface = new JavaScriptInterface();
myWebView.addJavascriptInterface(jsInterface, "Android");
Your method, and based on this other question:
Programmatically obtain the phone number of the Android phone
public class JavaScriptInterface {
@JavascriptInterface
public void getPhoneNumber() {
// Code to get phone number on android
TelephonyManager tMgr = (TelephonyManager)mAppContext.getSystemService(Context.TELEPHONY_SERVICE);
String phoneNumber = tMgr.getLine1Number();
}
}
On Web:
<a href="#" onclick="getPhoneNumber()">getMyNumber</a>
You could send a response to webview also. see this tutorial. it is in Koltin but if you need make that, you could write it on java.
https://medium.com/@elye.project/making-android-interacting-with-web-app-921be14f99d8
Based on this you could make some code like this:
myWebView.loadUrl("javascript: " +"returnPhoneNumber(\"" + phoneNumber + "\")", null);
you would need a function in js called "returnPhoneNumber"
Don't forget put Permission in manifest:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
if you are using a newer Android Version you would need implement permissionrequest.
I hope it helps.