简单的Phonegap振动插件无法正常工作

时间:2014-05-07 02:19:22

标签: cordova plugins vibration

我很困惑为什么即使像振动这样最简单的Phonegap插件也无法在我的iOS和Android设备上运行。我也试过所有其他插件失败了。我已经找不到问题所在的线索。我使用Phonegap Build,我在Mac上的Dreamweaver上开发。

这是激活我从网上获得的振动功能的基本代码。有人可以帮我解决问题吗?

<html>
  <head>
    <title>Notification Example</title>

    <script type="text/javascript" charset="utf-8" src="phonegap.js"></script>
    <script type="text/javascript" charset="utf-8">

    // Wait for PhoneGap to load
    //
    document.addEventListener("deviceready", onDeviceReady, false);

    // PhoneGap is ready
    //
    function onDeviceReady() {
        navigator.notification.vibrate(2000);
    }

    // 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);
        navigator.notification.vibrate(2500);
    }

    // Vibrate for 2 seconds
    //
    function vibrate() {
        navigator.notification.vibrate(2000);
    }

    </script>
  </head>
  <body>
  <br><br>

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

这是config.xml文件。为了发布这个帖子,我已经用占位符替换了我的域名和电子邮件。

   <?xml version="1.0" encoding="UTF-8" ?>
    <widget xmlns = "http://www.w3.org/ns/widgets"
        xmlns:gap = "http://phonegap.com/ns/1.0"
        id        = "com.mydomain"
        version   = "1.0.0">

    <name>Vibration Test App</name>

    <description>
    Testing vibration feature
    </description>

    <author href="http://mydomain.com" email="abc@mydomain.com">My name</author>

        <preference name="phonegap-version" value="3.4.0" />
        <preference name="orientation" value="default" />
        <preference name="fullscreen" value="true" />
        <preference name="target-device" value="universal" />
        <preference name="webviewbounce" value="true" />
        <preference name="prerendered-icon" value="true" />
        <preference name="stay-in-webview" value="true" />
        <preference name="ios-statusbarstyle" value="black-opaque" />
        <preference name="detect-data-types" value="true" />
        <preference name="exit-on-suspend" value="true" />
        <preference name="show-splash-screen-spinner" value="true" />
        <preference name="auto-hide-splash-screen" value="true" />
        <preference name="EnableViewportScale" value="false" />
        <preference name="MediaPlaybackRequiresUserAction" value="false" />
        <preference name="AllowInlineMediaPlayback" value="false" />
        <preference name="BackupWebStorage" value="cloud" />
        <preference name="TopActivityIndicator" value="gray" />
        <preference name="KeyboardDisplayRequiresUserAction" value="true" />
        <preference name="HideKeyboardFormAccessoryBar" value="false" />
        <preference name="SuppressesIncrementalRendering" value="false" />
        <preference name="android-minSdkVersion" value="7" />
        <preference name="android-installLocation" value="auto" />
        <preference name="SplashScreenDelay" value="0" />
        <preference name="ErrorUrl" value=""/>
        <preference name="BackgroundColor" value=""/>
        <preference name="KeepRunning" value="true"/>
        <preference name="DisallowOverscroll" value="false"/>
        <preference name="LoadingDialog" value=","/> 
        <preference name="LoadUrlTimeoutValue" value="20000" />
        <preference name="disable-cursor" value="true" />
        <gap:platform name="ios" />
        <gap:platform name="android" />
        <feature name="http://api.phonegap.com/1.0/camera"/>
        <feature name="http://api.phonegap.com/1.0/file"/>
        <feature name="http://api.phonegap.com/1.0/geolocation"/>
        <feature name="http://api.phonegap.com/1.0/media"/>
        <feature name="http://api.phonegap.com/1.0/notification"/>
        <gap:plugin name="org.apache.cordova.battery-status"  />
        <gap:plugin name="org.apache.cordova.camera"  />
        <gap:plugin name="org.apache.cordova.console"  />
        <gap:plugin name="org.apache.cordova.contacts"  />
        <gap:plugin name="org.apache.cordova.device"  />
        <gap:plugin name="org.apache.cordova.device-orientation"  />
        <gap:plugin name="org.apache.cordova.device-motion"  />
        <gap:plugin name="org.apache.cordova.dialogs"  />
        <gap:plugin name="org.apache.cordova.file"  />
        <gap:plugin name="org.apache.cordova.file-transfer"  />
        <gap:plugin name="org.apache.cordova.geolocation"  />
        <gap:plugin name="org.apache.cordova.globalization"  />
        <gap:plugin name="org.apache.cordova.inappbrowser"  />
        <gap:plugin name="org.apache.cordova.media"  />
        <gap:plugin name="org.apache.cordova.media-capture"  />
        <gap:plugin name="org.apache.cordova.network-information"  />
        <gap:plugin name="org.apache.cordova.splashscreen"  />
        <gap:plugin name="org.apache.cordova.vibration"  />
        <icon src="res/icon/android/icon-36-ldpi.png" gap:platform="android" gap:density="ldpi" />
        <icon src="res/icon/android/icon-48-mdpi.png" gap:platform="android" gap:density="mdpi" />
        <icon src="res/icon/android/icon-72-hdpi.png" gap:platform="android" gap:density="hdpi" />
        <icon src="res/icon/android/icon-96-xhdpi.png" gap:platform="android" gap:density="xhdpi" />
        <icon src="icon.png" />
        <gap:splash src="res/screen/android/screen-ldpi-portrait.png" gap:platform="android" gap:density="ldpi" />
        <gap:splash src="res/screen/android/screen-mdpi-portrait.png" gap:platform="android" gap:density="mdpi" />
        <gap:splash src="res/screen/android/screen-hdpi-portrait.png" gap:platform="android" gap:density="hdpi" />
        <gap:splash src="res/screen/android/screen-xhdpi-portrait.png" gap:platform="android" gap:density="xhdpi" />
        <access origin="*" />
        <gap:plugin name="com.phonegap.plugins.barcodescanner" />
        <gap:plugin name="com.pushwoosh.plugins.pushwoosh" />

    </widget>

1 个答案:

答案 0 :(得分:0)

参考Phonegap Doc

将通知功能添加到您的配置中。

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

如果你正在使用appbuilder,那应该这样做。如果您使用Eclipse和Android SDK自己构建它,则需要为AndroidManifest.xml添加权限:

<uses-permission android:name="android.permission.VIBRATE" />