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

使用config.xml控制Android插件安装:移除振动权限失败求助

解决Cordova config.xml移除Android振动权限无效的问题

你当前用<custom-preference>标签删除振动权限的方式不对,这个标签并非Cordova官方用来操作AndroidManifest权限的标准配置,所以不会生效。下面是两种可行的解决方法:

方法一:使用<remove-permission>标签(推荐,Cordova Android 7.0及以上版本支持)

直接在platform name="android"节点内添加以下代码,它会直接移除对应的权限:

<platform name="android">
        <preference name="Scheme" value="http" />
        <edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application" xmlns:android="http://schemas.android.com/apk/res/android">
            <application android:networkSecurityConfig="@xml/network_security_config" />
        </edit-config>
        <!-- 替换原来的custom-preference为这行 -->
        <remove-permission android:name="android.permission.VIBRATE" />
        <resource-file src="resources/android/xml/network_security_config.xml" target="app/src/main/res/xml/network_security_config.xml" />
        <allow-intent href="market:*" />
    </platform>

方法二:使用<config-file>标签删除权限

如果你的Cordova版本较低,不支持<remove-permission>,可以用<config-file>定位到权限节点并删除:

<platform name="android">
        <preference name="Scheme" value="http" />
        <edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application" xmlns:android="http://schemas.android.com/apk/res/android">
            <application android:networkSecurityConfig="@xml/network_security_config" />
        </edit-config>
        <!-- 替换原来的custom-preference为这段 -->
        <config-file parent="/manifest" target="AndroidManifest.xml" xmlns:android="http://schemas.android.com/apk/res/android">
            <uses-permission android:name="android.permission.VIBRATE" remove="true" />
        </config-file>
        <resource-file src="resources/android/xml/network_security_config.xml" target="app/src/main/res/xml/network_security_config.xml" />
        <allow-intent href="market:*" />
    </platform>

替换完成后重新编译项目,振动权限就会从生成的AndroidManifest.xml中移除。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.07 15:15:37