zoukankan      html  css  js  c++  java
  • Phonegap 通知 Notification

    通知 Notification

    一、notification.alert

    对话框 notification.alert

    响铃 notification.beep

     震动 notification.vibrate

    1. 增加插件

    cordova plugin add cordova-plugin-network-information

    cordova plugin add cordova-plugin-dialogs

    2. 在网络掉线的时候弹出Dialog

     使用navigator.notification.alert 这个方法,

     navigator.notification.alert('掉线了',
            app.alertDismissed,
            '网络状态',
                '知道了'
            );

    alertDismissed是关闭时候的方法

        alertDismissed: function(){
            console.log("关掉了");
        },
    

      

    3. 断网后效果如下图

    二、确认通知

    notification.confirm

    1. 可以定制多个按钮

        //显示对话框
        showConfirm: function(){
            navigator.notification.confirm('软件有新版本了',
            app.onConfirm,
            '软件更新',
            ['以后再说','立即下载']);
        },
    
    onConfirm为点击按钮的方法
        //点击不同按钮要做的事
        onConfirm: function(buttonIndex){
            if(buttonIndex == 1){
                console.log("以后再说");
            }else{
                console.log("立即下载");
            }
        },
    

      buttonIndex从1开始



    2. 在onDeviceReady中调用此方法

     3. 最终效果图

     

    三、提示窗口

    notification.prompt

    对话框中带有文本框

    1. 调用方法

        //带有文本框的dialog
        showPrompt:function(){
            navigator.notification.prompt(
                '请输入文本',
                app.onPrompt,
                '注册',
                ['取消','确认'],
                '张三丰'
            )
        },
    

      onPrompt方法

       onPrompt:function(result){
           console.log("用户点击了按钮: " +result.buttonIndex + '用户输入的内容:' + result.input1);
       },
    

      

    2 效果图:

  • 相关阅读:
    sqlite 修改 id 自增值
    欧拉图与哈密顿图12:22
    nps 配置 vnc内网穿透
    0 范数、1 范数、2 范数有什么区别?
    相关测试
    golang学习笔记---channel(通道)
    golang学习笔记---pflag包
    Nginx+Keepalived配置Nginx自动启动和7*24不间断服务
    Keepalived+Nginx双机主备配置实践
    虚拟机中使用域名通过宿主window访问
  • 原文地址:https://www.cnblogs.com/linlf03/p/7069920.html
Copyright © 2011-2022 走看看