You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Cordova振动插件无法正常工作问题求助

Troubleshooting Cordova Vibration Plugin Issues (Device Not Muted)

Hey David, sorry to hear you're hitting a wall with the Cordova vibration plugin not working even after confirming your device isn't muted. Let's walk through some targeted checks and fixes that often resolve this kind of issue:

  • Verify Plugin-Cordova Version Compatibility
    Outdated or mismatched versions are a common culprit. First, uninstall the current plugin and reinstall the latest compatible version:

    cordova plugin remove cordova-plugin-vibration
    cordova plugin add cordova-plugin-vibration@latest
    

    Double-check that the plugin version supports your installed Cordova release (e.g., Cordova 10+ requires plugin v3.0.0+).

  • Confirm Platform Permissions

    • For Android: Open your project's platforms/android/app/src/main/AndroidManifest.xml and ensure this permission is present:
      <uses-permission android:name="android.permission.VIBRATE" />
      
    • For iOS: Basic vibration doesn't require special permissions, but if you're using background vibration, enable the "Background Modes" capability in Xcode and check "Audio, AirPlay, and Picture in Picture".
  • Ensure Code Runs After deviceready
    Cordova APIs only work once the deviceready event fires—this is a super common mistake! Test with this minimal working example:

    document.addEventListener("deviceready", onDeviceReady, false);
    
    function onDeviceReady() {
        // Test a 2-second vibration
        navigator.vibrate(2000);
        // Or test a pattern: vibrate 1s, pause 0.5s, vibrate 1s
        // navigator.vibrate([1000, 500, 1000]);
    }
    
  • Check Device-Specific Restrictions
    Many custom Android ROMs (like Xiaomi, Huawei, or Samsung) have aggressive power-saving or app permission controls:

    • Go to your device's Settings > Apps > [Your App] > Permissions and confirm "Vibrate" is enabled.
    • Disable any battery-saving modes that might block app vibrations in the background.
  • Rule Out Project Conflicts
    Create a fresh, minimal Cordova project with only the vibration plugin installed. If vibration works here, your original project likely has a conflict with another plugin or custom code. Gradually add back your other plugins/code to identify the culprit.

  • Inspect Console Logs
    Run your app with verbose logging to catch initialization errors:

    # For Android
    cordova run android --log
    # For iOS, use Xcode's console or run:
    cordova run ios --log
    

    Look for messages like Vibration plugin not initialized or permission errors—these will point you directly to the issue.

If none of these steps resolve the problem, share your Cordova version, plugin version, target device model/OS version, and any relevant error logs, and we can dig deeper!

内容的提问来源于stack exchange,提问作者David Danielyan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 06:22:47