[JAVA] What to do if SPA URL loading cannot be detected by WebView shouldOverrideUrlLoading

Introduction

I think it's a common way to use shouldOverrideUrlLoading to detect URL loading in Android's WebView, but for pages like SPA (single page application) where submit doesn't run, this method detects events. I can't.

manner

Use the WebViewClient's doUpdateVisitedHistory. doUpdateVisitedHistory is a database of visited links The method to update.

mWebView.setWebViewClient( new WebViewClient(){
            @TargetApi(Build.VERSION_CODES.LOLLIPOP)
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
                Log.d(TAG, "shouldOverrideUrlLoading LOLLIPOP url = " + request.getUrl().toString());
                return false;
            }

            @SuppressWarnings("deprecation")
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                Log.d(TAG, "shouldOverrideUrlLoading url = " + url);
                return false;
            }

            @Override
            public void doUpdateVisitedHistory(WebView view, String url, boolean isReload) {
                Log.d(TAG, "doUpdateVisitedHistory url = " + url);
            }
        });

Now, let's access the SPA from WebView.

06-29 10:10:50.756 13453-13453/jp.sample D/WebViewFragment: doUpdateVisitedHistory url = https://xxxx/profile/home
06-29 10:34:41.636 13453-13453/jp.sample D/WebViewFragment: doUpdateVisitedHistory url = https://xxxx/connect
06-29 10:34:41.658 13453-13453/jp.sample D/WebViewFragment: doUpdateVisitedHistory url = https://xxxx/logout
06-29 10:34:41.671 13453-13453/jp.sample D/WebViewFragment: doUpdateVisitedHistory url = https://xxxx/connect
06-29 10:34:44.131 13453-13453/jp.sample D/WebViewFragment: doUpdateVisitedHistory url = https://xxxx/signin
06-29 10:34:54.526 13453-13453/jp.sample D/WebViewFragment: doUpdateVisitedHistory url = https://xxxx/auth/callback?token=xxxx

I was able to detect it safely!

Recommended Posts

What to do if SPA URL loading cannot be detected by WebView shouldOverrideUrlLoading
What to do if the adb command cannot be executed
What to do if JavaMail cannot be used with OpenJDK 11 or later
What to do if rails server can't be stopped
What to do if the build fails with the error "Module compiled with Swift x.x.x cannot be imported by the Swift x.x.x compiler"
What to do if you cannot roll back the migration (UnknownMigrationVersionError)
What to do when CentOS cannot be started with VirtualBox on Catalina
[Composer] [Laravel] What to do if you cannot install due to insufficient memory
What to do if deployment fails on Heroku (Ruby app not detected)
What to do if you don't like the code generated by swagger-codegen-cli
What to do if you install Ubuntu
What to do if you can't activate the select box created by bootstrap-select
[Ubuntu] What to do when MongoDB cannot be started due to a SocketException error
What to do if the server tomcat dies
What to do if you push incorrect information
What to do if mvn archetype: generate fails
[React.useRef] What to do when the latest state cannot be referenced in the event listener
What to do if you cannot execute with the command "Java package name / class name"
What to do if the debug gem installation fails
What to do if the Rails server can't start
What to do if ClassNotFoundException occurs when starting Tomcat
What to do if TextToSpeech doesn't work on Android 11
What to do if you accidentally create a model
What to do if an ActionController :: UnknownFormat error occurs
[Rails] What to do when rails db: migrate cannot be done because there is no table referenced by the foreign key
What to do if password authentication fails in Docker/Postgres
[Java] [Spring] What to do if you cannot Autowire with Type Mismatch after annotating Spring Security
What to do when Git Repository cannot be displayed in Team Explorer for Eclipse in Azure
What to do if you get a java.io.IOException in GlassFish
What to do if audio is not available on discordrb
# What to do if you accidentally do rails db: migrate: drop
What to do when Cannot apply expression operators to method binding
What to do if mysql2 gets a bundle install error
What to do if you can't use the rails command
What to do about the "cannot be read or is not a valid ZIP file" error