'Hide sound recording notification programatically in Android 12
Solution 1:[1]
While writing the question, I found a hacky solution:
webView.getEngine().getLoadWorker().stateProperty().addListener((o, oldState, newState) -> {
if(newState == Worker.State.SUCCEEDED) {
try {
String newContent = new String(Files.readAllBytes(Paths.get(new URI(getClass().getResource("/test.html").toExternalForm()))), "UTF-8");
webView.getEngine().executeScript("document.documentElement.innerHTML = '" + newContent.replace("'", "\\'").replace("\n", "\\n") + "'");
} catch(Exception e) {
e.printStackTrace();
}
}
});
Solution 2:[2]
I found another simple solution using Spark Java:
WebViewTest.java
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
import spark.Spark;
import spark.staticfiles.StaticFilesConfiguration;
public class WebViewTest extends Application {
public static void main(String[] args) {
Application.launch(args);
}
@Override
public void start(Stage stage) {
Spark.port(8000);
StaticFilesConfiguration staticHandler = new StaticFilesConfiguration();
staticHandler.configure("/");
Spark.before((req, res) -> {
if(req.url().endsWith(".html")) staticHandler.putCustomHeader("Content-Type", "text/html; charset=UTF-8");
else staticHandler.putCustomHeader("Content-Type", null);
staticHandler.consume(req.raw(), res.raw());
});
Spark.init();
WebView webView = new WebView();
webView.getEngine().load("http://localhost:8000/test.html");
Scene scene = new Scene(webView, 500, 500);
stage.setScene(scene);
stage.setTitle("WebView Test");
stage.show();
}
}
test.html
<!DOCTYPE html>
<html>
<body>
<p>RIGHT SINGLE QUOTATION MARK: ’</p>
<p>Image:</p>
<img src="image.png">
</body>
</html>
image.png
Result:
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Henry Sanger |
| Solution 2 | Henry Sanger |




