Да, это возможно. Я уже делал много javascript-инъекций для веб-сайта раньше. Вам просто нужно ввести свой собственный javascript на любой сайт.
Например
//simple javascript to pass value from javascript to native app
String javascript = "javascript:function testHello(){return Android.hello('HAI'); testHello();}"
webview.setWebViewClient(new WebViewClient() {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
//put your function in string and load the javascript when the page is finished load
view.loadUrl(javascript);
}
});
// 'Android' is your variable key for triggering the function ex: Android.hello(), Android.calculate()
// you can change to other name like 'APP', so in javascript be like this ex: APP.hello(), APP.calculate()
webview.addJavascriptInterface(new WebAppInterface(this), "Android");
//load website
webview.loadUrl(PageUrl);
В WebAppInterface где вы создаете функцию для обнаружения JavaScript вы впрыснуть ранее
public class WebAppInterface {
Activity mContext;
public WebAppInterface(Activity c) {
mContext = c;
}
//this function will get your value from the javascript earlier.
//Android.hello('value')
@JavascriptInterface
public void hello(String value){
//you will get HAI message in here
Log.i("TAG",value);
}
}