0

我正在尝试使用锁定模式库在我的应用程序中实现一些安全性

我已经按照这里的每一步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;
        }
    }
} 
4

2 回答 2

0

Android-lockpattern 已停止。你可能想试试这个库。它允许您在自己的活动中使用锁定模式,而不是在自己的活动中。希望能帮助到你!

于 2014-07-02T21:29:07.627 回答
0

替换这一行 editor.putString("pattern", pattern.toString()); 到 editor.putString("pattern", new String(pattern));

于 2013-12-10T10:41:15.270 回答