[SpaccDotWeb.Android] Add missing changes

This commit is contained in:
2025-02-13 19:39:54 +01:00
parent 7093760d38
commit 5338c8aaf6
6 changed files with 212 additions and 128 deletions

View File

@@ -24,6 +24,7 @@
<li><a href="data:text/plain;utf8,Hello World!">data:text/plain</a></li>
<li><a href="data:text/html;utf8,&lt;h2&gt;Hello World!">data:text/html</a></li>
<li><a href="mailto:example@example.com">mailto:</a></li>
<li><a href="intent://#Intent;action=android.intent.action.VIEW;scheme=http;type=video/mp4;end">intent://</a></li>
</ul>
<h3>Files</h3>
<p>Upload: <label><input type="file"/></label></p>

View File

@@ -1,9 +1,12 @@
package org.eu.spacc.spaccdotweb.android.webview;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.webkit.WebView;
import org.eu.spacc.spaccdotweb.android.utils.ApiUtils;
import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.List;
@@ -19,12 +22,24 @@ public class WebViewClient extends android.webkit.WebViewClient {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO: This should not override all HTTP links if the app loads from remote (which will allow proper internal navigation and file downloads)
// NOTE: It seems like the WebView overrides loading of data: URIs before we can get it here...
List<String> protocols = Arrays.asList("data", "http", "https", "mailto", "ftp");
if (protocols.contains(url.toLowerCase().split(":")[0])) {
ApiUtils.openOrShareUrl(context, Uri.parse(url));
List<String> externalProtocols = Arrays.asList("data", "http", "https", "mailto", "ftp");
String protocol = url.toLowerCase().split(":")[0];
if (protocol.equals("file")) {
return super.shouldOverrideUrlLoading(view, url);
} else if (protocol.equals("intent")) {
ApiUtils.apiRun(4, () -> {
try {
// TODO: Should this handle broadcasts and services differently?
context.startActivity(Intent.parseUri(url, 0));
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
});
return true;
} else {
return super.shouldOverrideUrlLoading(view, url);
ApiUtils.openOrShareUrl(context, Uri.parse(url));
return true;
}
}
}