Уведомление

Уведомление

Уведомления о визуальных, звуковые и тактильные устройства.

Методы

Доступ к функции

Начиная с версии 3.0 Кордова реализует интерфейсы API уровень устройства как плагины. Использование CLI plugin команды, описанные в интерфейс командной строки, чтобы добавить или удалить эту функцию для проекта:

    $ cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-vibration.git
    $ cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs.git
    $ cordova plugin rm org.apache.cordova.core.dialogs
    $ cordova plugin rm org.apache.cordova.core.vibration

Эти команды применяются для всех целевых платформ, но изменить параметры конфигурации платформы, описанные ниже:

Некоторые платформы могут поддерживать эту функцию без необходимости специальной настройки. Смотрите поддержку платформы обзор.


Notification.Alert

Отображает окно пользовательские оповещения или диалоговое окно.

navigator.notification.alert(message, alertCallback, [title], [buttonName])

Описание

Большинство реализаций Cordova использовать диалоговое окно родной для этой функции, но некоторые платформы браузера alert функция, которая как правило менее настраивается.

Поддерживаемые платформы

Быстрый пример

// 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 причуды


notification.confirm

Отображает диалоговое окно Настраиваемый подтверждения.

navigator.notification.confirm(message, confirmCallback, [title], [buttonLabels])

Описание

notification.confirmМетод отображает родной диалоговое окно, которое более настраиваемый, чем в браузере confirm функции.

confirmCallback

confirmCallbackВыполняется, когда пользователь нажимает одну из кнопок в диалоговом окне подтверждения.

Аргументом функции обратного вызова buttonIndex (номер), который является индекс нажатой кнопки. Обратите внимание, что индекс использует единицы индексации, поэтому значение 1 , 2 , 3 , и т.д.

Поддерживаемые платформы

Быстрый пример

// 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 причуды


notification.prompt

Показывает настраиваемое диалоговое окно Ввод.

navigator.notification.prompt(message, promptCallback, [title], [buttonLabels], [defaultText])

Описание

notification.promptМетод отображает родной диалоговое окно, которое более настраиваемый, чем в браузере prompt функции.

promptCallback

promptCallbackВыполняется, когда пользователь нажимает одну из кнопок в диалоговом окне приглашения. resultsОбъект, переданный в метод обратного вызова содержит следующие свойства:

Поддерживаемые платформы

Быстрый пример

// 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>

Андроид причуды


Notification.beep

Устройство воспроизводит звуковой сигнал звук.

navigator.notification.beep(times);

Поддерживаемые платформы

Быстрый пример

// 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>

Андроид причуды

Windows Phone 7 и 8 причуды

Tizen причуды


notification.vibrate

Вибрирует устройство для указанного количества времени.

navigator.notification.vibrate(milliseconds)

Поддерживаемые платформы

Быстрый пример

// 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 причуды