Phonegap Notification.Alert Not Working

Notification.alert is not working in phonegap build 3.1.0

As of version 3.0, Phonegap/Cordova implements device-level APIs as plugins so you have to include this in your config.xml found in the www folder

<gap:plugin name="org.apache.cordova.dialogs" />

or add it manually from the phonegap CLI like this:

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

After you include it you can use like this

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

You can research further here . Happy coding!

Phonegap Firebase Push Notification not firing event listener when app opens, or when app is in background

My final answer, to get push messages working as both notification msg and in-app messages for Android devices (inc Android 8 and 9) was to do the following:

Add this to/modify from config.xml:

<preference name="phonegap-version" value="cli-9.0.0" />  
<platform name="android">
<resource-file src="google-services.json" target="app/google-services.json" />
</platform>
<platform name="ios">
<resource-file src="GoogleService-Info.plist" />
</platform>
<plugin name="phonegap-plugin-push" spec="2.1.3">
<variable name="SENDER_ID" value="xxxxxxxxxxxxx" />
</plugin>

Also when sending your packet data, send the "data" parameter AND the "notification" parameter, AND include the "content_available" flag, eg...

  $notification = [
'body' => $message,
'title' => $titlenotification,
"icon" => 'notification_icon',
"content_available" => "1",
];

$data = [
"title" =>$titlenotification,
"message" => $message,
"content_available" => "1",
];

$fields = [
'registration_ids' => $registrationtokens,
'notification' => $notification,
'data' => $data,
"priority" => "high",
"content_available" => true,
];

//send field data like curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );

...finally, be sure to add your google-services.json to the root folder, but also the www folder. Otherwise you will receive the error "A plugin requires google-services.json. The Google Services Plugin cannot function without it" when Phonegap Build is processing it.

This will show an notification message if the app is closed or in the background. when you click the notification it will open the app AND show the message again. If your app is in the background, when you bring it to the foreground is WILL show the message too. If your app is closed and you dont click the notification message then you will never see the message on your app.

Phonegap push notification does not appear in Status bar nor in Lock screen for iOS using the PushPlugin plugin

The push notification payload need an aps key, and an alert with the message that will be displayed:

For each notification, compose a JSON dictionary object (as defined by
RFC 4627). This dictionary must contain another dictionary identified
by the key aps. The aps dictionary can contain one or more properties
that specify the following user notification types

  • An alert message to display to the user
  • A number to badge the app icon with
  • A sound to play

More info

Payload example:

  {

"aps" : {

"alert" : "You got your emails.",

"badge" : 9,

"sound" : "bingbong.aiff"

},

"acme1" : "bar",

"acme2" : 42

}

When the app is in foreground you receive the whole payload and you can handle it even if it doesn't have that format, but when the app is in backgroud or closed, the system needs the aps key and the alert with the message that will be shown on the notification center.

phonegap navigator.notification.alert doesn't work

I built your project using Cordova CLI 3.0.9, using the command line tools and following the docs listed here (http://cordova.apache.org/docs/en/edge/cordova_notification_notification.md.html#Notification). I used your HTML and JS code and the dialog popped up just fine.

When looking through the other files, I noticed a difference in config.xml; my config.xml looks like this:

<?xml version='1.0' encoding='utf-8'?>
<widget id="io.cordova.helloCordova" version="2.0.0" xmlns="http://www.w3.org/ns/widgets">
<name>Hello Cordova</name>
<description>
A sample Apache Cordova application that responds to the deviceready event.
</description>
<author email="dev@cordova.apache.org" href="http://cordova.io">
Apache Cordova Team
</author>
<content src="index.html" />
<feature name="App">
<param name="android-package" value="org.apache.cordova.App" />
</feature>
<feature name="Vibration">
<param name="android-package" value="org.apache.cordova.vibration.Vibration" />
</feature>
<feature name="Notification">
<param name="android-package" value="org.apache.cordova.dialogs.Notification" />
</feature>
<access origin="*" />
<preference name="useBrowserHistory" value="true" />
<preference name="exit-on-suspend" value="false" />
<preference name="fullscreen" value="true" />
<preference name="webviewbounce" value="true" />
</widget>

Notice that mine has org.apache.cordova.dialogs.Notification - yours is missing the dialogs namespace for some reason. Is this on purpose? If you add "dialogs" namespace, does it work? What about if you rebuild using the latest CLI version?

Phonegap Build Firebase push notification on IOS not working (but working on Android)

The answer was to ensure that the correct APN and profile was in use. Push notification had not been included on the APN, and the profile must be for "prodduction" not development.

I hope that helps someone else.



Related Topics



Leave a reply



Submit