4
I have a little problem, I need to know the URL every time the page is changed.
my code works perfectly normally opens youtube that would be the example :
WebView wv;
public void onBackPressed(){
if(wv.canGoBack()){
wv.goBack();
}else{
super.onBackPressed();
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
wv = (WebView) findViewById(R.id.wv);
//Enable Javascript
wv.getSettings().setJavaScriptEnabled(true);
wv.setFocusableInTouchMode(true);
// set Render Priority to high
wv.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
wv.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
wv.getSettings().setDomStorageEnabled(true);
wv.getSettings().setAppCacheEnabled(true);
wv.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
// Load url
wv.loadUrl("https://www.youtube.com/");
wv.setWebViewClient(new WebViewClient());
}
I looked for solutions on foreign sites for my problem and found this one
WebView wv;
public void onBackPressed(){
if(wv.canGoBack()){
wv.goBack();
}else{
super.onBackPressed();
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
wv = (WebView) findViewById(R.id.wv);
//Enable Javascript
wv.getSettings().setJavaScriptEnabled(true);
wv.setFocusableInTouchMode(true);
// set Render Priority to high
wv.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
wv.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
wv.getSettings().setDomStorageEnabled(true);
wv.getSettings().setAppCacheEnabled(true);
wv.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
// Load url
wv.loadUrl("https://www.youtube.com/");
wv.setWebViewClient(new myWebViewClient());
}
String currentUrl;
private class myWebViewClient extends WebViewClient{
@Override
public boolean shouldOverrideUrlLoading (WebView view, String url){
Log.e("URL Now",url);
currentUrl=url;
view.loadUrl(url); // se eu usar isso, já não fica em branco a inicial, mas msm assim não alerta qndo muda de URL
return true;
}
}
I checked the logs and saw that appeared the URL as soon as opened the APP, but did not open youtube, the screen is all white.
My first example works perfectly, but does not meet my needs.
My goal is to know is to detect when I click on a video, so I need to know.
Is there any other more elegant way to do that ?
I’ll open the project here and test it now before I go to the gym.
– Bruno R
Poxa cara worked perfectly, thanks, but it takes all same kkkk, I turn with the regex to filter the page, thanks even.
– Bruno R