0

In Android Studio I get this warning shouldOverrideUrlLoading is Deprecated if I add this line @SuppressWarnings("deprecation") I dont get anymore the warning but is it correct to do that? This is the code I use

public class MyAppWebViewClient extends WebViewClient {

    @SuppressWarnings("deprecation")
    @Override
    public boolean shouldOverrideUrlLoading(WebView view,  String url) {
        if(Uri.parse(url).getHost().length() == 0) {
            return false;
        }

        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        view.getContext().startActivity(intent);
        return true;
    }
}
Zoel
  • 85
  • 8

1 Answers1

4

Check this CommonsWare answer.

But, in any way, use @SuppressWarnings isn't a solution.

Community
  • 1
  • 1
Volodymyr Yatsykiv
  • 3,181
  • 1
  • 24
  • 28
  • That helped a lot Volodymyr I followed the advice from the answer you gave me and it worked, only thing i changed after I used the `WebResourceRequest request` was the `minSdkVersion` in gradle from 19 to 21 cause the `request.getUrl` asked for a different api. – Zoel Apr 09 '17 at 19:00
  • @Zoel In that case users with devices with Android lower than Lollipop will not be able to install your application. In that case, you have to implement something if(Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { //deprecated method } else { //new method } – Volodymyr Yatsykiv Apr 10 '17 at 08:36
  • Thank you @Volodymyr-Yatsykiv, I noticed that too, I appreciate your help. – Zoel Apr 10 '17 at 18:42