JavaScript xdiseñadores

Notification

http://docs.phonegap.com/es/1.0.0/phonegap_notification_notification.md.html#Notification

La notificación tiene los siguientes métodos:

  • notification.alert
  • notification.confirm
  • notification.prompt
  • notification.beep
  • notification.vibrate

Android necesita incluir los siguientes parámetros en el config XML:

<feature name="Notification">
<param name="android-package" value="org.apache.cordova.dialogs.Notification" />
</feature>
<feature name="Vibration">
<param name="android-package" value="org.apache.cordova.vibration.Vibration" />
</feature>

Algo similar en iOs

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

notification.alert

Para mostrar una caja de alerta se usa:

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

  • message: Dialog message. (String)
  • alertCallback: Llamada a una función
  • title: Título (String) por defecto to Alert
  • buttonName: Nombre del botón. (String) por defecto OK

Description

Cordova usa su propia implementación de cajas de diálogo. En algunas plataformas se emplea la alerta del navegador.

Ejemplo

// Amazon Fire OS / 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
);

notification.confirm

Caja de confirmación:

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

  • message: Mensaje (String)
  • confirmCallback: Llamada a la función según botón presionado (1, 2, or 3)
  • title: Título (String) por defecto to Confirm
  • buttonLabels: Array de strings especificando las etiquetas de los botones. (Array) por defecto [OK,Cancel]

Ejemplo

// 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
);
}

notification.beep

notificar con un sonido de beep.

navigator.notification.beep(times);

  • times: El número de veces que repite el beep. (Number)

Ejemplo

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

notification.vibrate

Especifica la vibración en tiempo.

navigator.notification.vibrate(milliseconds)

  • time: En milisegundos. (Number)

Ejemplo

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