Reputation: 578
I use Webview
to play a site that have video inside. And it response the URL of the video in Log-cat. I wonder is there a way that I can get the link and toast it. Or there is another way that I can get the link faster instead of using Webview
?
Here is my code:
String url = "https://www.youtube.com/watch?v=U14K1YfVjN8";
WebView webView;
webView = findViewById(R.id.webView);
String newUA= "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36";
webView.getSettings().setUserAgentString(newUA);
webView.getSettings().setDomStorageEnabled(false);
webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
webView.getSettings().setGeolocationEnabled(false);
webView.getSettings().setSupportZoom(false);
webView.loadUrl(url );
Upvotes: 0
Views: 97
Reputation: 2086
You can use WebChromeClient's onConsoleMessage callback to get console messages from the webview.
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.setWebChromeClient(new WebChromeClient() {
public void onConsoleMessage(String message, int lineNumber, String
sourceID) {
Log.d("MyApplication", message + " -- From line "
+ lineNumber + " of "
+ sourceID);
return true;
}
});
or
public boolean onConsoleMessage(ConsoleMessage cm) {
Log.d("MyApplication", cm.message() + " -- From line "
+ cm.lineNumber() + " of "
+ cm.sourceId() );
return true;
}
Upvotes: 2