PhoneGap 通知

通知

可視、 可聽,和觸覺設備通知

方法

訪問功能

從 3.0 版,科爾多瓦作為外掛程式實現了設備級 Api。 使用 CLI 的 plugin 命令,描述在命令列介面,可以添加或刪除一個專案,為此功能:

    $ cordova plugin add org.apache.cordova.dialogs
    $ cordova plugin add org.apache.cordova.vibration
    $ cordova plugin ls
    [ 'org.apache.cordova.dialogs',
      'org.apache.cordova.vibration' ]
    $ cordova plugin rm org.apache.cordova.dialogs
    $ cordova plugin rm org.apache.cordova.vibration

這些命令適用于所有有針對性的平臺,但修改如下所述的特定于平臺的配置設置:

  • Android 系統

    (in app/res/xml/config.xml)
    <feature name="Notification">
        <param name="android-package" value="org.apache.cordova.Notification" />
    </feature>
    
    
    (in app/AndroidManifest.xml)
    <uses-permission android:name="android.permission.VIBRATE" />
    
  • 黑莓手機 WebWorks

    (in www/plugins.xml)
    <feature name="Notification">
        <param name="blackberry-package" value="org.apache.cordova.notification.Notification" />
    </feature>
    
    
    (in www/config.xml)
    <feature id="blackberry.ui.dialog" />
    
  • (在 iOSconfig.xml)

    <feature name="Notification">
        <param name="ios-package" value="CDVNotification" />
    </feature>
    

一些平臺可能支援此功能,而無需任何特殊的配置。請參見在概述部分中的平臺支援

notification.alert

顯示一個自訂的警報或對話方塊框。

navigator.notification.alert(message, alertCallback, [title], [buttonName])
  • 消息: 消息對話方塊。(字串)

  • alertCallback: 當警報對話方塊的被解雇時要調用的回(函數)

  • 標題: 標題對話方塊。(字串)(可選,預設值為Alert)

  • buttonName: 按鈕名稱。(字串)(可選,預設值為OK)

說明

大多數科爾多瓦實現使用本機對話方塊中的此項功能,但一些平臺使用瀏覽器的 alert 函數,這是通常不那麼可自訂。

支援的平臺

  • Android 系統
  • 黑莓手機 WebWorks (OS 5.0 和更高)
  • iOS
  • Tizen
  • Windows Phone 7 和 8
  • Windows 8

快速的示例

// Android / BlackBerry WebWorks (OS 5.0 and higher) / iOS / Tizen
//
function alertDismissed() {
    // do something
}

navigator.notification.alert(
    'You are the winner!',  // message
    alertDismissed,         // callback
    'Game Over',            // title
    'Done'                  // buttonName
);

完整的示例

<!DOCTYPE html>
<html>
  <head>
    <title>Notification Example</title>

    <script type="text/javascript" charset="utf-8" src="cordova.js"></script>
    <script type="text/javascript" charset="utf-8">

    // Wait for device API libraries to load
    //
    document.addEventListener("deviceready", onDeviceReady, false);

    // device APIs are available
    //
    function onDeviceReady() {
        // Empty
    }

    // alert dialog dismissed
        function alertDismissed() {
            // do something
        }

    // Show a custom alertDismissed
    //
    function showAlert() {
        navigator.notification.alert(
            'You are the winner!',  // message
            alertDismissed,         // callback
            'Game Over',            // title
            'Done'                  // buttonName
        );
    }

    </script>
  </head>
  <body>
    <p><a href="#" onclick="showAlert(); return false;">Show Alert</a></p>
  </body>
</html>

Windows Phone 7 和 8 怪癖

  • 有沒有內置瀏覽器警報,但你可以綁定一個,如下所示調用 alert() 在全球範圍內:

    window.alert = navigator.notification.alert;
    
  • 兩個 alertconfirm 的非阻塞的調用,其中的結果才是可用的非同步。

notification.confirm

顯示一個可自訂的確認對話方塊。

navigator.notification.confirm(message, confirmCallback, [title], [buttonLabels])
  • 消息: 消息對話方塊。(字串)

  • confirmCallback: 要用索引 (1、 2 或 3) 按下的按鈕,或者在沒有按下按鈕 (0) 駁回了對話方塊中時調用的回(函數)

  • 標題: 標題對話方塊。(字串)(可選,預設值為Confirm)

  • buttonLabels: 指定按鈕標籤的字串陣列。(陣列)(可選,預設值為 [ OK,Cancel ])

說明

notification.confirm方法顯示一個本機的對話方塊,更可自訂的瀏覽器比 confirm 函數。

confirmCallback

confirmCallback當使用者按下確認對話方塊中的按鈕之一的時候執行。

將參數 buttonIndex (編號),它是按下的按鈕的索引。 請注意索引使用基於 1 的索引,所以值是 123 ,等等。

支援的平臺

  • Android 系統
  • 黑莓手機 WebWorks (OS 5.0 和更高)
  • iOS
  • Tizen
  • Windows Phone 7 和 8
  • Windows 8

快速的示例

// process the confirmation dialog result
function onConfirm(buttonIndex) {
    alert('You selected button ' + buttonIndex);
}

// Show a custom confirmation dialog
//
function showConfirm() {
    navigator.notification.confirm(
        'You are the winner!', // message
         onConfirm,            // callback to invoke with index of button pressed
        'Game Over',           // title
        ['Restart','Exit']         // buttonLabels
    );
}

完整的示例

<!DOCTYPE html>
<html>
  <head>
    <title>Notification Example</title>

    <script type="text/javascript" charset="utf-8" src="cordova.js"></script>
    <script type="text/javascript" charset="utf-8">

    // Wait for device API libraries to load
    //
    document.addEventListener("deviceready", onDeviceReady, false);

    // device APIs are available
    //
    function onDeviceReady() {
        // Empty
    }

    // process the confirmation dialog result
    function onConfirm(buttonIndex) {
        alert('You selected button ' + buttonIndex);
    }

    // Show a custom confirmation dialog
    //
    function showConfirm() {
        navigator.notification.confirm(
            'You are the winner!', // message
             onConfirm,            // callback to invoke with index of button pressed
            'Game Over',           // title
            ['Restart','Exit']         // buttonLabels
        );
    }

    </script>
  </head>
  <body>
    <p><a href="#" onclick="showConfirm(); return false;">Show Confirm</a></p>
  </body>
</html>

Windows Phone 7 和 8 怪癖

  • 有沒有內置的瀏覽器功能的 window.confirm ,但你可以將它綁定通過分配:

    window.confirm = navigator.notification.confirm;
    
  • 調用到 alertconfirm 的非阻塞,所以結果就是只可用以非同步方式。

notification.prompt

顯示一個可自訂的提示對話方塊。

navigator.notification.prompt(message, promptCallback, [title], [buttonLabels], [defaultText])
  • 消息: 消息對話方塊。(字串)

  • promptCallback: 當按下按鈕時要調用的回(函數)

  • 標題: 對話方塊的標題(字串) (可選,預設值為Prompt)

  • buttonLabels: 陣列,這些字串指定按鈕標籤(陣列) (可選,預設值為["OK","Cancel"])

  • defaultText: 預設文字方塊中輸入值 ( String ) (可選,預設值: 空字串)

說明

notification.prompt方法顯示一個本機的對話方塊,更可自訂的瀏覽器比 prompt 函數。

promptCallback

promptCallback當使用者按下一個提示對話方塊中的按鈕時執行。results物件傳遞給回的包含以下屬性:

  • buttonIndex: 按下的按鈕的索引。(人數)請注意索引使用基於 1 的索引,所以值是 123 ,等等。

  • 輸入 1: 在提示對話方塊中輸入的文本。(字串)

支援的平臺

  • Android 系統
  • iOS

快速的示例

// process the promp dialog results
function onPrompt(results) {
    alert("You selected button number " + results.buttonIndex + " and entered " + results.input1);
}

// Show a custom prompt dialog
//
function showPrompt() {
    navigator.notification.prompt(
        'Please enter your name',  // message
        onPrompt,                  // callback to invoke
        'Registration',            // title
        ['Ok','Exit'],             // buttonLabels
        'Jane Doe'                 // defaultText
    );
}

完整的示例

<!DOCTYPE html>
<html>
  <head>
    <title>Notification Prompt Dialog Example</title>

    <script type="text/javascript" charset="utf-8" src="cordova.js"></script>
    <script type="text/javascript" charset="utf-8">

    // Wait for device API libraries to load
    //
    document.addEventListener("deviceready", onDeviceReady, false);

    // device APIs are available
    //
    function onDeviceReady() {
        // Empty
    }

    // process the promptation dialog result
    function onPrompt(results) {
        alert("You selected button number " + results.buttonIndex + " and entered " + results.input1);
    }

    // Show a custom prompt dialog
    //
    function showPrompt() {
        navigator.notification.prompt(
            'Please enter your name',  // message
            onPrompt,                  // callback to invoke
            'Registration',            // title
            ['Ok','Exit'],             // buttonLabels
            'Jane Doe'                 // defaultText
        );
    }

    </script>
  </head>
  <body>
    <p><a href="#" onclick="showPrompt(); return false;">Show Prompt</a></p>
  </body>
</html>

Android 的怪癖

  • Android 支援最多的三個按鈕,並忽略任何更多。

  • 關於 Android 3.0 及更高版本,使用全息主題的設備按相反的順序顯示按鈕。

notification.beep

設備播放提示音聲音。

navigator.notification.beep(times);
  • 時間: 的次數重複發出蜂鳴音。(人數)

支援的平臺

  • Android 系統
  • 黑莓手機 WebWorks (OS 5.0 和更高)
  • iOS
  • Tizen
  • Windows Phone 7 和 8

快速的示例

// Beep twice!
navigator.notification.beep(2);

完整的示例

<!DOCTYPE html>
<html>
  <head>
    <title>Notification Example</title>

    <script type="text/javascript" charset="utf-8" src="cordova.js"></script>
    <script type="text/javascript" charset="utf-8">

    // Wait for device API libraries to load
    //
    document.addEventListener("deviceready", onDeviceReady, false);

    // device APIs are available
    //
    function onDeviceReady() {
        // Empty
    }

    // Show a custom alert
    //
    function showAlert() {
        navigator.notification.alert(
            'You are the winner!',  // message
            'Game Over',            // title
            'Done'                  // buttonName
        );
    }

    // Beep three times
    //
    function playBeep() {
        navigator.notification.beep(3);
    }

    // Vibrate for 2 seconds
    //
    function vibrate() {
        navigator.notification.vibrate(2000);
    }

    </script>
  </head>
  <body>
    <p><a href="#" onclick="showAlert(); return false;">Show Alert</a></p>
    <p><a href="#" onclick="playBeep(); return false;">Play Beep</a></p>
    <p><a href="#" onclick="vibrate(); return false;">Vibrate</a></p>
  </body>
</html>

Android 的怪癖

  • Android 系統播放的預設通知鈴聲*設置/聲音和顯示*面板下指定。

Windows Phone 7 和 8 怪癖

  • 依賴泛型蜂鳴音從科爾多瓦分佈。

Tizen 怪癖

  • Tizen 通過播放音訊檔通過媒體 API 實現會發出蜂鳴聲。

  • 蜂鳴音必須很短,必須設在 sounds 子目錄中的應用程式的根目錄中,並且必須命名beep.wav.

notification.vibrate

為指定的時間量振動設備

navigator.notification.vibrate(milliseconds)
  • 時間: 毫秒為單位) 在震動的設備,其中 1000年毫秒等於 1 秒。(人數)

支援的平臺

  • Android 系統
  • 黑莓手機 WebWorks (OS 5.0 和更高)
  • iOS
  • Windows Phone 7 和 8

快速的示例

// Vibrate for 2.5 seconds
//
navigator.notification.vibrate(2500);

完整的示例

<!DOCTYPE html>
<html>
  <head>
    <title>Notification Example</title>

    <script type="text/javascript" charset="utf-8" src="cordova.js"></script>
    <script type="text/javascript" charset="utf-8">

    // Wait for device API libraries to load
    //
    document.addEventListener("deviceready", onDeviceReady, false);

    // device APIs are available
    //
    function onDeviceReady() {
        // Empty
    }

    // Show a custom alert
    //
    function showAlert() {
        navigator.notification.alert(
            'You are the winner!',  // message
            'Game Over',            // title
            'Done'                  // buttonName
        );
    }

    // Beep three times
    //
    function playBeep() {
        navigator.notification.beep(3);
    }

    // Vibrate for 2 seconds
    //
    function vibrate() {
        navigator.notification.vibrate(2000);
    }

    </script>
  </head>
  <body>
    <p><a href="#" onclick="showAlert(); return false;">Show Alert</a></p>
    <p><a href="#" onclick="playBeep(); return false;">Play Beep</a></p>
    <p><a href="#" onclick="vibrate(); return false;">Vibrate</a></p>
  </body>
</html>

iOS 的怪癖

BB10 的怪癖

震動功能導航器物件所擁有的

    navigator.vibrate(1000);  // vibrate for 1 second
深度学习是机器学习的一个子领域,它基于人工神经网络的研究,特别是利用多层次的神经网络来进行学习和模式识别。深度学习模型能够学习数据的高层次特征,这些特征对于图像和语音识别、自然语言处理、医学图像分析等应用至关重要。以下是深度学习的一些关键概念和组成部分: 1. **神经网络(Neural Networks)**:深度学习的基础是人工神经网络,它是由多个层组成的网络结构,包括输入层、隐藏层和输出层。每个层由多个神经元组成,神经元之间通过权重连接。 2. **前馈神经网络(Feedforward Neural Networks)**:这是最常见的神经网络类型,信息从输入层流向隐藏层,最终到达输出层。 3. **卷积神经网络(Convolutional Neural Networks, CNNs)**:这种网络特别适合处理具有网格结构的数据,如图像。它们使用卷积层来提取图像的特征。 4. **循环神经网络(Recurrent Neural Networks, RNNs)**:这种网络能够处理序列数据,如时间序列或自然语言,因为它们具有记忆功能,能够捕捉数据中的时间依赖性。 5. **长短期记忆网络(Long Short-Term Memory, LSTM)**:LSTM 是一种特殊的 RNN,它能够学习长期依赖关系,非常适合复杂的序列预测任务。 6. **生成对抗网络(Generative Adversarial Networks, GANs)**:由两个网络组成,一个生成器和一个判别器,它们相互竞争,生成器生成数据,判别器评估数据的真实性。 7. **深度学习框架**:如 TensorFlow、Keras、PyTorch 等,这些框架提供了构建、训练和部署深度学习模型的工具和库。 8. **激活函数(Activation Functions)**:如 ReLU、Sigmoid、Tanh 等,它们在神经网络中用于添加非线性,使得网络能够学习复杂的函数。 9. **损失函数(Loss Functions)**:用于评估模型的预测与真实值之间的差异,常见的损失函数包括均方误差(MSE)、交叉熵(Cross-Entropy)等。 10. **优化算法(Optimization Algorithms)**:如梯度下降(Gradient Descent)、随机梯度下降(SGD)、Adam 等,用于更新网络权重,以最小化损失函数。 11. **正则化(Regularization)**:技术如 Dropout、L1/L2 正则化等,用于防止模型过拟合。 12. **迁移学习(Transfer Learning)**:利用在一个任务上训练好的模型来提高另一个相关任务的性能。 深度学习在许多领域都取得了显著的成就,但它也面临着一些挑战,如对大量数据的依赖、模型的解释性差、计算资源消耗大等。研究人员正在不断探索新的方法来解决这些问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值