From b4d3709da556071ab0ba538b2a89611b795e0ea1 Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Tue, 13 Jul 2021 21:15:11 +0900 Subject: [PATCH] Explicitly add http scheme if missing. Fixes austinhuang0131/barinsta#1642 --- app/src/main/java/awais/instagrabber/utils/Utils.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/utils/Utils.java b/app/src/main/java/awais/instagrabber/utils/Utils.java index 78f30eef..a2a4e19b 100644 --- a/app/src/main/java/awais/instagrabber/utils/Utils.java +++ b/app/src/main/java/awais/instagrabber/utils/Utils.java @@ -195,10 +195,15 @@ public final class Utils { if (context == null || TextUtils.isEmpty(url)) { return; } - final Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); - i.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName()); - i.putExtra(Browser.EXTRA_CREATE_NEW_TAB, true); try { + String url1 = url; + // add http:// if string doesn't have http:// or https:// + if (!url.startsWith("http://") && !url.startsWith("https://")) { + url1 = "http://" + url; + } + final Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url1)); + i.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName()); + i.putExtra(Browser.EXTRA_CREATE_NEW_TAB, true); context.startActivity(i); } catch (ActivityNotFoundException e) { Log.e(TAG, "openURL: No activity found to handle URLs", e);