phonegap navigator.notification.alert doesn't work

后端 未结 6 1049
时光说笑
时光说笑 2021-01-02 01:48

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

sources: www/index.html:



    
        

        
相关标签:
6条回答
  • 2021-01-02 02:15

    You will only see working from the android emulator or a device, in ripple does not work.

        var app = {
        // Application Constructor
        initialize: function() {        
            document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
        },
    
        // deviceready Event Handler
        //
        // Bind any cordova events here. Common events are:
        // 'pause', 'resume', etc.
        onDeviceReady: function() {
            //this.receivedEvent('deviceready');
                console.log(navigator.notification);
    
                navigator.notification.alert(
                        'You are the winner!',  // message
                        alertDismissed,         // callback
                        'Game Over',            // title
                        'Done'                  // buttonName
                    );
                //navigator.notification.beep(2);
        },
    
        // 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);
        }
    };app.initialize();
    
    0 讨论(0)
  • 2021-01-02 02:17

    Reinstal APK App on device. It is only when the system is installed that the system consents to the permissions. Only rebuild does not work. After reinstall the permissions are displayed on the screen and active.

    0 讨论(0)
  • 2021-01-02 02:34

    try to add this feature to your config.xml file

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

    ...and a good advice to copy the config.xml file to your www directory.

    0 讨论(0)
  • 2021-01-02 02:37

    All that you have to do is add this feature to your project... Stand up con the phonegap project folder (not the platform folder), for example: cd MobileAplications/MyPhoneGapExample then, add the plugin (I installed cordova instead off phonegap, so I suposed if you install phonegap you have to use the "phonegap" command): cordova plugin add org.apache.cordova.dialogs

    I hope it works for you!!

    PD: If someone dont know whats the difference between the platform folder and the project folder, here is the document that can show the difference: http://docs.phonegap.com/en/3.2.0/guide_cli_index.md.html#The%20Command-Line%20Interface

    0 讨论(0)
  • 2021-01-02 02:41

    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?

    0 讨论(0)
  • 2021-01-02 02:41

    I am using visual studio 2015, and I solved this problem by adding the Notification plugin.

    Double click your config.xml in your poject, and select Notification plugin and install.

    0 讨论(0)
提交回复
热议问题