Android Webview桌面通知支持

时间:2018-08-12 04:14:29

标签: javascript android webview

我正在尝试实现我的桌面通知的网络视图。在桌面应用程序中,我已经使用以下Javascript代码实现了桌面通知的使用

function notifyMe() {
    // Let's check if the browser supports notifications
    if (!("Notification" in window)) {
        alert("This browser does not support desktop notification");
    }

    // Let's check whether notification permissions have already been granted
    else if (Notification.permission === "granted") {
        // If it's okay let's create a notification
        var notification = new Notification("Hi there!");
    }

    // Otherwise, we need to ask the user for permission
    else if (Notification.permission !== "denied") {
        Notification.requestPermission(function (permission) {
            // If the user accepts, let's create a notification
            if (permission === "granted") {
                var notification = new Notification("Hi there!");
            }
        });
    }

    // At last, if the user has denied notifications, and you
    // want to be respectful there is no need to bother them any more.
}

当我在android应用程序中打开视图时,显示警告,表明该设备不支持桌面通知。但是,使用移动浏览器(Chrome),此代码使我允许请求通知,但无法在桌面界面中给我相同的通知。非常感谢:)

2 个答案:

答案 0 :(得分:0)

您应该像这里View this

那样发送未决的意图

答案 1 :(得分:0)

访问此链接以获取完整的片段教程。我已通过本教程了解了有关片段的信息。 它是管理员在教程中的完整回复 Tutorial