allow opening http sites in external browser with warning.

#16
This commit is contained in:
woheller69 2025-04-26 14:57:34 +02:00
parent e5fffc6d53
commit 80ba774035
4 changed files with 33 additions and 5 deletions

View file

@ -222,7 +222,19 @@ public class MainActivity extends Activity {
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
} else if (request.getUrl().toString().startsWith("http://")){
new AlertDialog.Builder(context)
.setTitle(R.string.title_open_link)
.setIcon(R.drawable.ic_warning) // Set the alert icon
.setMessage(context.getString(R.string.text_warning_link) + "\n\n" + context.getString(R.string.text_open_link, request.getUrl().toString()))
.setNegativeButton(android.R.string.cancel, null)
.setPositiveButton(
android.R.string.ok,
(dialogInterface, i) ->
startActivity(new Intent(Intent.ACTION_VIEW, request.getUrl()))
)
.create()
.show();
}
return true; //Deny URLs that aren't HTTPS
}
@ -245,7 +257,7 @@ public class MainActivity extends Activity {
if (!allowed) {
Log.d(TAG, "[shouldOverrideUrlLoading][NOT ON ALLOWLIST] Blocked access to " + request.getUrl().getHost());
if (request.getUrl().toString().startsWith("https://")) {
(new AlertDialog.Builder(context)
new AlertDialog.Builder(context)
.setTitle(R.string.title_open_link)
.setMessage(context.getString(R.string.text_open_link, request.getUrl().toString()))
.setNegativeButton(android.R.string.cancel, null)
@ -254,9 +266,8 @@ public class MainActivity extends Activity {
(dialogInterface, i) ->
startActivity(new Intent(Intent.ACTION_VIEW, request.getUrl()))
)
)
.create()
.show();
.create()
.show();
}
return true; //Deny URLs not on ALLOWLIST

View file

@ -0,0 +1,15 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M12,5.99L19.53,19H4.47L12,5.99M12,2L1,21h22L12,2L12,2z"
android:fillColor="@android:color/holo_red_dark"/>
<path
android:pathData="M13,16l-2,0l0,2l2,0z"
android:fillColor="#000000"/>
<path
android:pathData="M13,10l-2,0l0,5l2,0z"
android:fillColor="#000000"/>
</vector>

View file

@ -8,6 +8,7 @@
<string name="no_app_installed">Keine App installiert</string>
<string name="title_open_link">Link öffnen</string>
<string name="text_open_link">In externem Browser öffnen? %s</string>
<string name="text_warning_link">ACHTUNG: Dieser Link ist nicht sicher!</string>
<string name="dialog_StarOnGitHub">Mögen Sie diese App? Bitte vergeben Sie einen Stern auf GitHub oder spendieren Sie dem Entwickler einen Kaffee über PayPal.</string>
<string name="dialog_Later_button">Vielleicht später</string>
</resources>

View file

@ -7,6 +7,7 @@
<string name="no_app_installed">No app installed</string>
<string name="title_open_link">Open link</string>
<string name="text_open_link">Open in external browser? %s</string>
<string name="text_warning_link">WARNING: This link is not secure!</string>
<string name="dialog_StarOnGitHub">Do you like this app? Please give a star on GitHub or buy the developer a coffee via PayPal.</string>
<string name="dialog_Later_button">Maybe later</string>
</resources>