I've been attempting to update the URL of my webview by invoking a function with AngularJs, but unfortunately, I haven't been successful.
Below is my Angular class:
app.controller("speechController", function($scope){
$scope.page = 'index.html';
$scope.url = function(page){
Android.receivePage();
}
});
And here is my Java class:
public class MainActivity extends AppCompatActivity {
Button b;
CustomWebViewClient customWebViewClient;
WebView myWebView;
private TextToSpeech tts;
private final int REQ_CODE_SPEECH_INPUT = 100;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
myWebView = (WebView) findViewById(R.id.webView);
myWebView.addJavascriptInterface(this, "Android");
myWebView.setWebViewClient(new WebViewClient());
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
myWebView.loadUrl("file:///android_asset/index.html");
b= (Button) findViewById(R.id.button);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
receivePage();
}
});
}
@JavascriptInterface
public void receivePage() {
myWebView.loadUrl("file:///android_asset/index.html");
}
}
It's worth noting that I included a button in onCreate to test the receivePage function. Through debugging, I observed that both the Angular function and the button onClick function successfully call receivePage(), but only the button correctly updates the URL. It is crucial for my project to use Angular to modify the webview. Can anyone provide insight into why my code is behaving in this manner?