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

能否通过cordova-plugin-root-detection实现APK安装前Root权限检测?

Can Cordova + cordova-plugin-root-detection detect root before app installation?

Absolutely! You can implement root/jailbreak detection for your Cordova cross-platform app using the cordova-plugin-root-detection plugin, but there's an important clarification to make first:

You can't run any code before the app is installed on the device—since the app isn't present yet to execute detection logic. Instead, you'll want to run the root check as soon as the app launches for the first time, then block access or notify the user if a rooted/jailbroken device is detected.

Here's how to set this up:

1. Install the plugin

First, add the plugin to your Cordova project via the command line:

cordova plugin add cordova-plugin-root-detection

2. Implement the detection logic

Cordova plugins require the deviceready event to fire before they can be used, so wrap your detection code in that handler. Here's a practical example:

document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady() {
    // Check if the device is rooted/jailbroken
    RootDetection.isRooted(function(isRooted) {
        if (isRooted) {
            // Rooted device detected: inform user and exit the app
            navigator.notification.alert(
                "This application does not support rooted or jailbroken devices. Please uninstall and use it on a non-modified device.",
                function() {
                    // Exit the app after user acknowledges the alert
                    navigator.app.exitApp();
                },
                "Unsupported Device",
                "OK"
            );
        } else {
            // Non-rooted device: proceed with normal app initialization
            console.log("Device is safe. Launching app...");
            // Add your app's startup logic here (e.g., load main screen, initialize services)
        }
    }, function(error) {
        // Handle detection errors (e.g., plugin failed to load)
        console.error("Failed to check root status: ", error);
        // You might choose to default to blocking access here, or proceed with caution
    });
}

Key Notes

  • Cross-platform support: This plugin works for both Android (root detection) and iOS (jailbreak detection), covering the most common modified device scenarios.
  • Detection limitations: No root/jailbreak check is 100% foolproof—some advanced users may bypass basic detection. This is a deterrent, not an absolute security barrier.
  • User experience: Always provide clear feedback to users about why access is blocked, so they understand the reason instead of facing a mysterious app crash or exit.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.15 07:46:10