phonegap navigator.notification.alert doesn't work

3,172 views
Skip to first unread message

Panagiotis Raditsas

unread,
Sep 16, 2013, 9:35:13 AM9/16/13
to phon...@googlegroups.com
Hello as mentioned in http://stackoverflow.com/questions/18827959/phonegap-navigator-notification-alert-doesnt-work
I'm facing the follwoing issue. No luck the past 7 hours to resolve it.. I' appreciate any help.

The title is self explanatory, I ca't figure out why tho.

sources:
www/index.html:

    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="utf-8" />
            <meta name="format-detection" content="telephone=no" />
            <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
            <link rel="stylesheet" type="text/css" href="css/index.css" />
            <title>Hello World</title>
        </head>
        <body>
            <div class="app">
                <h1>PhoneGap</h1>
                <div id="deviceready" class="blink">
                    <p class="event listening">Connecting to Device</p>
                    <p class="event received">Device is Ready</p>
                </div>
            </div>
            <script type="text/javascript" src="phonegap.js"></script>
            <script type="text/javascript" src="js/index.js"></script>
            <script type="text/javascript">
                app.initialize();
            </script>
        </body>
    </html>

index.js:

    var app = {
        // Application Constructor
        initialize: function() {
            this.bindEvents();
        },
        // Bind Event Listeners
        //
        // Bind any events that are required on startup. Common events are:
        // 'load', 'deviceready', 'offline', and 'online'.
        bindEvents: function() {
            document.addEventListener('deviceready', this.onDeviceReady, false);
        },
        // deviceready Event Handler
        //
        // The scope of 'this' is the event. In order to call the 'receivedEvent'
        // function, we must explicity call 'app.receivedEvent(...);'
        onDeviceReady: function() {
            app.receivedEvent('deviceready');
        },
        // Update DOM on a Received Event
        receivedEvent: function(id) {
            var parentElement = document.getElementById(id);
            var listeningElement = parentElement.querySelector('.listening');
            var receivedElement = parentElement.querySelector('.received');
    
            listeningElement.setAttribute('style', 'display:none;');
            receivedElement.setAttribute('style', 'display:block;');
    
            console.log('Received Event: ' + id);
    
            navigator.notification.alert('PhoneGap Alert', null, 'Title', 'Button');
        }
    };


config.xml in android/res/xml:

    <?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="d...@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="Notification">
            <param name="android-package" value="org.apache.cordova.Notification" />
        </feature>
        <access origin="http://127.0.0.1*" />
        <preference name="useBrowserHistory" value="true" />
        <preference name="exit-on-suspend" value="false" />
        <preference name="permissions" value="none" />
        <preference name="orientation" value="default" />
        <preference name="target-device" value="universal" />
        <preference name="fullscreen" value="true" />
        <preference name="webviewbounce" value="true" />
        <preference name="prerendered-icon" value="true" />
        <preference name="stay-in-webview" value="false" />
        <preference name="ios-statusbarstyle" value="black-opaque" />
        <preference name="detect-data-types" value="true" />
        <preference name="show-splash-screen-spinner" value="true" />
        <preference name="auto-hide-splash-screen" value="true" />
        <preference name="disable-cursor" value="false" />
        <preference name="android-minSdkVersion" value="8" />
        <preference name="android-installLocation" value="auto" />
    </widget>

and androidmanifest.xml:

    <?xml version='1.0' encoding='utf-8'?>
    <manifest android:hardwareAccelerated="true" android:versionCode="1" android:versionName="1.0.0" android:windowSoftInputMode="adjustPan" package="com.acs.acs_mobile" xmlns:android="http://schemas.android.com/apk/res/android">
        <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
        <uses-permission android:name="android.permission.INTERNET" />
        <uses-permission android:name="android.permission.VIBRATE" />
        <application android:debuggable="true" android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name">
            <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/app_name" android:name="main" android:theme="@android:style/Theme.Black.NoTitleBar">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
        </application>
        <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="18" />
    </manifest>

I'm trying to figure out why it doesn't work with no luck for the past hours.
I'm realtivley new to phonegap so please If I'm missing something let me know...

PS. Phonegap -version : 3.0.0-0.14.3 , device sdk 8 , AVD sdk 8 (both same result)

**Update** after wrapping the code inside a try catch I got this error message:

    result of expression 'navigator.notification' undefined is not an object


The cause is : `Likely the name of phonegap*js or cordova*js in your index.html does not match the file name in the assets/www directory.` but I only have phonegap.js and cordova.js in platforms/android/assets/www and I'm including with the exact same name... Still can't figure this out...

Joram Teusink

unread,
Sep 17, 2013, 9:40:39 AM9/17/13
to phon...@googlegroups.com
Navigator is not defined, meaning that PhoneGap/Cordova ain't properly loaded. I suggest you move away from 3.0.0 and go to 3.0.9 (or at least the latest) to sort out bugs in the first release(s) of PhoneGap iteration 3.

Op maandag 16 september 2013 15:35:13 UTC+2 schreef Panagiotis Raditsas:

Cam

unread,
Oct 7, 2013, 8:05:41 PM10/7/13
to phon...@googlegroups.com

包四維

unread,
Oct 8, 2013, 4:39:20 AM10/8/13
to phon...@googlegroups.com
Have you ever try these code to see the phonegap loaded Success or not ?
<script type="text/javascript">
document.addEventListener("deviceready", checkDevice, false);
function checkDevice()
{
alert(device.cordova);
}
</script>

Cam於 2013年10月8日星期二UTC+8上午8時05分41秒寫道:

der_sebastian

unread,
Oct 9, 2013, 7:48:00 PM10/9/13
to phon...@googlegroups.com
I am having the same issue. I have copied the full example from the phonegap docs into my www>index.html (from http://docs.phonegap.com/en/3.0.0/cordova_notification_notification.md.html#Notification) and added the notification plugin as described.


Using the example and pressing the link renders this only:

2013-10-09 16:46:53.503 contactsApp[23498:c07] CDVPlugin class CDVNotification (pluginName: Notification) does not exist.

2013-10-09 16:46:53.503 contactsApp[23498:c07] ERROR: Plugin 'Notification' not found, or is not a CDVPlugin. Check your plugin mapping in config.xml.

2013-10-09 16:46:53.503 contactsApp[23498:c07] -[CDVCommandQueue executePending] [Line 117] FAILED pluginJSON = [

  "Notification1206224055",

  "Notification",

  "alert",

  [

    "You are the winner!",

    "Game Over",

    "Done"

  ]

]

How can I get this to work again? Thanks for any pointers.

-S

Jessica Wadsworth

unread,
Dec 5, 2013, 4:44:42 PM12/5/13
to phon...@googlegroups.com
Today... I had the same trouble, but... I found what was wrong, Phonegap don't recognize the action, so...all that you have to do is install the feature in the console like this:

stand up in the phonegap project folder (not the platform project), for example: cd MobileAplications/MyPhoneGapProject
then install the feature, I install cordova instead off phonegap, so I used: cordova plugin add org.apache.cordova.dialogs
and this will solve the trouble.

So, remember... that kind of error is thrown when we haven't add plugins/features to our projects.
And now... we can enjoy our code!!
Good luck!!

I hope it works for you.

Roshan Shrestha

unread,
Mar 27, 2014, 5:31:43 AM3/27/14
to phon...@googlegroups.com
:( having same issue with latest version 3.4.0 as well.

The 

navigator.notification.alert

is not working says undefined method.

Regards,
Roshan

jignesh patel

unread,
May 7, 2014, 10:50:43 AM5/7/14
to phon...@googlegroups.com
same error and yes installed via cli.
but one thing i see. is same code is working on the Ondevice ready index.js file but wont work in html page index.html in set interval. in andoird

jignesh patel

unread,
May 7, 2014, 10:51:43 AM5/7/14
to phon...@googlegroups.com
hi i also got same error . yes my device.cordova is working ok. 

jignesh patel

unread,
May 7, 2014, 10:54:42 AM5/7/14
to phon...@googlegroups.com
tired this but wont working

jcesarmobile

unread,
May 7, 2014, 11:06:28 AM5/7/14
to phon...@googlegroups.com
You can't use phonegap API until the device ready is fired
Reply all
Reply to author
Forward
0 new messages