android-lockpattern库比较失败

时间:2013-11-06 01:48:12

标签: android

我正在尝试使用锁定模式库

在我的应用程序中实现一些安全性

我已经按照这里的每一步https://code.google.com/p/android-lockpattern/wiki/QuickUse 由于某种原因,我的代码[下面]触发LockPatternActivity.RESULT_FAILED 所有LockPatternActivity意图都正常运行

public void buttonClick() {

    _prefs = getPreferences(MODE_PRIVATE);
    String restoredText = _prefs.getString("pattern", null);

    if(restoredText== null)
    {
        Intent intent = new Intent(LockPatternActivity.ACTION_CREATE_PATTERN, null, this, LockPatternActivity.class);
        startActivityForResult(intent, REQ_CREATE_PATTERN);
    }
    else
    {
        char[] savedPattern = restoredText.toCharArray();

        Intent intent = new Intent(LockPatternActivity.ACTION_COMPARE_PATTERN, null,
                this, LockPatternActivity.class);

        intent.putExtra(LockPatternActivity.EXTRA_PATTERN, savedPattern);
        startActivityForResult(intent, REQ_ENTER_PATTERN);
    }
}


@Override
protected void onActivityResult(int request, int result, Intent data) {

    char[] pattern = data.getCharArrayExtra(LockPatternActivity.EXTRA_PATTERN);

    if (request == REQ_CREATE_PATTERN) {
        if (result == RESULT_OK) {
            editor.putString("pattern", pattern.toString());
            editor.apply();
        }

    } else if (request == REQ_ENTER_PATTERN) {
        switch (result) {
            case RESULT_OK:
                break;
            case RESULT_CANCELED:
                // The user cancelled the task
                break;
            case LockPatternActivity.RESULT_FAILED:
                // The user failed to enter the pattern
                break;
            case LockPatternActivity.RESULT_FORGOT_PATTERN:
                // The user forgot the pattern and invoked your recovery Activity.
                break;
        }
    }
} 

2 个答案:

答案 0 :(得分:0)

替换此行editor.putString(" pattern",pattern.toString()); to editor.putString(" pattern",new String(pattern));

答案 1 :(得分:0)

Android-lockpattern已停止。您可能希望尝试使用this库。它允许您在自己的活动中使用锁定模式,而不是在其自己的活动中使用。希望它有所帮助!