From 26e652d0ce80d2d70991d8311feebf0513534210 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonhard=20K=C3=BCnzler?= Date: Sun, 27 Sep 2020 01:48:36 +0200 Subject: [PATCH] Handle waweb redirect to whatsapp homepage Should fix #28 --- .../whatsappwebtogo/WebviewActivity.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/kuenzler/whatsappwebtogo/WebviewActivity.java b/app/src/main/java/io/kuenzler/whatsappwebtogo/WebviewActivity.java index 4b633be..96d92de 100644 --- a/app/src/main/java/io/kuenzler/whatsappwebtogo/WebviewActivity.java +++ b/app/src/main/java/io/kuenzler/whatsappwebtogo/WebviewActivity.java @@ -65,8 +65,11 @@ public class WebviewActivity extends AppCompatActivity implements NavigationView private static final String AUDIO_PERMISSION = Manifest.permission.RECORD_AUDIO; // "android.permission.RECORD_AUDIO"; private static final String[] VIDEO_PERMISSION = {CAMERA_PERMISSION, AUDIO_PERMISSION}; + private static final String WHATSAPP_HOMEPAGE_URL = "https://www.whatsapp.com/"; + + private static final String WHATSAPP_WEB_BASE_URL = "web.whatsapp.com"; private static final String WORLD_ICON = "\uD83C\uDF10"; - private static final String WHATSAPP_WEB_URL = "https://web.whatsapp.com" + private static final String WHATSAPP_WEB_URL = "https://" + WHATSAPP_WEB_BASE_URL + "/" + WORLD_ICON + "/" + Locale.getDefault().getLanguage(); @@ -237,7 +240,16 @@ public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request Uri url = request.getUrl(); Log.d(DEBUG_TAG, url.toString()); - if (url.getHost().equals("web.whatsapp.com")) { + if (url.toString().equals(WHATSAPP_HOMEPAGE_URL)){ + // when whatsapp somehow detects that waweb is running on a phone (e.g. trough + // the user agent, but apparently somehow else), it automatically redicts to the + // WHATSAPP_HOMEPAGE_URL. It's higly unlikely that a user wants to visit the + // WHATSAPP_HOMEPAGE_URL from within waweb. + // -> block the request and reload waweb + showToast("WA Web has to be reloaded to keep the app running"); + loadWhatsapp(); + return true; + } else if (url.getHost().equals(WHATSAPP_WEB_BASE_URL)) { // whatsapp web request -> fine return super.shouldOverrideUrlLoading(view, request); } else {