Skip to content

Commit

Permalink
Handle waweb redirect to whatsapp homepage
Browse files Browse the repository at this point in the history
Should fix #28
  • Loading branch information
92lleo committed Sep 26, 2020
1 parent 12ae1b5 commit 26e652d
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions app/src/main/java/io/kuenzler/whatsappwebtogo/WebviewActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 26e652d

Please sign in to comment.