1

当出现一定数量的屏幕密码失败时,我试图让 Android 手机(LP 5.1.1)重新启动。这是我在 Keyguard 中的语言:

if (mLockPatternUtils.isSeparateEncryptionPasswordEnabled() && failedAttempts >= 5) {
        final PowerManager powerManager = mContext.getSystemService(PowerManager.class);
        powerManager.reboot(null);

我得到一个编译错误:

frameworks/base/packages/Keyguard/src/com/android/keyguard/KeyguardSecurityContainer.java:409: 

错误:类 Context 中的方法 getSystemService 不能应用于给定类型;final PowerManager powerManager = mContext.getSystemService(PowerManager.class); ^ 必需:字符串

发现:类

原因:实际参数类不能转换为

字符串按方法调用转换

有任何想法吗?提前致谢

4

1 回答 1

1

我不会使用 PowerManager.class,而是使用Context.POWER_SERVICE

或者也许只是:

    if (mLockPatternUtils.isSeparateEncryptionPasswordEnabled() &&vfailedAttempts >= 5) { 
           final PowerManager powerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); 
           powerManager.reboot(null);
    }

您必须将 Context 添加到您的导入中。

当然,如果您的目标手机已ROOTED:

Runtime.getRuntime().exec(new String[]{"/system/bin/su","-c","reboot now"});

就足够了。

于 2016-06-17T23:37:08.587 回答