2016-05-04 31 views
1

リフレクションを使用して、デバイスの画面を無効に設定しています。キーパッドをdisabled.myとして設定します。アンドロイドのバージョンが4.4.2.whileの場合、例外が発生します。java.lang.reflect.InvocationTargetExceptionjava.lang.SecurityException:LockSettingsWrite:ユーザー10096も現在のプロセスもandroid.permission.ACCESS_KEYGUARD_SECURE_STORAGEを持っていません。反射を使用してデバイスの画面のロックを解除する

私は私のコードこのエラーはキットカットで発生するのはなぜか

try{ 
    Class lockPatternUtilsCls = Class.forName("com.android.internal.widget.LockPatternUtils"); 
    Constructor lockPatternUtilsConstructor = lockPatternUtilsCls.getConstructor(new Class[]{Context.class}); 
    Object lockPatternUtils = lockPatternUtilsConstructor.newInstance(ChangeDeviceLockMode.this); 

    Method clearLockMethod = lockPatternUtils.getClass().getMethod("clearLock", boolean.class); 
    clearLockMethod.setAccessible(true); 
    Method setLockScreenDisabledMethod = lockPatternUtils.getClass().getMethod("setLockScreenDisabled", boolean.class); 
    setLockScreenDisabledMethod.setAccessible(true); 
    clearLockMethod.invoke(lockPatternUtils, false); 
    setLockScreenDisabledMethod.invoke(lockPatternUtils, true);  
    Toast.makeText(ChangeDeviceLockMode.this,"none", Toast.LENGTH_LONG).show(); 
}catch(Exception e){ 
    System.err.println("An InvocationTargetException was caught!"); 
    Throwable cause = e.getCause(); 

    Toast.makeText(ChangeDeviceLockMode.this,"none"+e, Toast.LENGTH_LONG).show(); 
} 
Toast.makeText(ChangeDeviceLockMode.this,"Yupiee!!! Password changed successfully to swipe", Toast.LENGTH_LONG).show(); 
} 
+0

コードがJellybeanで完全に動作します? –

+0

私の要件がkitkatに固有であるために試したことはありません – tanmeet

答えて

0

この例外を是正を教えてください共有しています:キットカットアンドロイドで

は、アプリケーションデータからセキュリティデータベースを離れて移動します領域(/ data/data)からシステムデータ領域(/ data/system)に移動します。

Ref

+0

おかげで完璧な答えがたくさんありました。私の評判スコアがあなたのためにあなたのために投票することはできませんstill11.Howeverたくさんありがとうございます – tanmeet

+0

助けあれば、 。 :) –

関連する問題