You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android端浏览器是否支持Notifications Web API?示例无法正常显示通知的问题咨询

Android端浏览器是否支持Notifications Web API?示例无法正常显示通知的问题咨询

我做了一个展示Notifications Web API基础用法的示例,在Windows和Linux系统的Firefox、Chrome浏览器中都能正常运行,通知可以正常弹出。

不过在Android系统的Chrome和Brave浏览器里,这个示例完全没有任何通知显示出来。

我查阅了Web API相关文档,既找不到关于Android端如何使用Notifications API的指引,也没有看到官方明确说明这个API在Android上不支持的内容。所以想请教大家:Android系统到底支持Web API的Notifications功能吗?

以下是我的示例代码:

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Notifications example</title>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />

        <!-- Bootstrap/JQuery. -->
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css" integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous" />
        <script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
        <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
        <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.min.js" integrity="sha384-+sLIOodYLS7CIrQpBjl+C7nPvqq+FbNUBDunl/OZv93DB7Ln/533i8e/mZXLi/P+" crossorigin="anonymous"></script>
    </head>
    <body class="container mt-3">
        <h2 class="mt-5">Notifications example</h2>

        <p>This example use only JavaScript. No server side used.</p>

        <input type="button" id="subscribe" value="Subscribe" class="btn btn-success" /><br />

        <button onclick="notifyMe()" class="btn btn-info mt-3">Notify me!</button>

        <button onclick="notifyMeWith7SecDelay()" class="btn btn-info mt-3">Notify me with 7 sec delay!</button>

        <script>
            $("#subscribe").on("click", function () {
                let promise = Notification.requestPermission();
            });

            function notifyMe() {
                if (!("Notification" in window)) {
                    alert("This browser does not support desktop notification");
                } else if (Notification.permission === "granted") {
                    const notification = new Notification("Hi there!", {
                        body: "Is an example of a notification"
                    });
                } else if (Notification.permission !== "denied") {
                    Notification.requestPermission().then((permission) => {
                        if (permission === "granted") {
                            const notification = new Notification("Hi there!", {
                                body: "Is an example of a notification"
                            });
                        }
                    });
                }
            }

            function notifyMeWith7SecDelay() {
                setTimeout(notifyMe, 7000);
            }
        </script>
    </body>
</html>

备注:内容来源于stack exchange,提问作者BrilliantContract

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.15 10:44:51