简体   繁体   English

指纹验证成功后如何在android中移动到第二个布局

[英]How to move to second layout in android after fingerprint authentication successful

I have made the first layout in android as fingerprint authentication and it has successfully authenticate my fingerprint but how to make it move from the fingerprint layout directly to the second layout... 我已经在Android中将第一个布局作为指纹身份验证,它已经成功验证了我的指纹,但是如何使它从指纹布局直接移至第二个布局...

Please anyone help me....... 请任何人帮助我.......

This is the coding of FingerprintAuthenticationActivity.java : 这是FingerprintAuthenticationActivity.java的编码:

public class FingerprintAuthenticationActivity extends AppCompatActivity {

private static final String KEY_NAME = "example_key";
private FingerprintManager fingerprintManager;
private KeyguardManager keyguardManager;
private KeyStore keyStore;
private KeyGenerator keyGenerator;
private Cipher cipher;
private FingerprintManager.CryptoObject cryptoObject;
private FingerprintHandler fingerprintHandler;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_fingerprint_authentication);

    keyguardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
    fingerprintManager = (FingerprintManager) getSystemService(FINGERPRINT_SERVICE);

    if (!keyguardManager.isKeyguardSecure()) {

        Toast.makeText(this, "Lock screen security not enabled in Settings",
                Toast.LENGTH_LONG).show();
        return;
    }

    if (ActivityCompat.checkSelfPermission(this,
            Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
        Toast.makeText(this, "Fingerprint authentication permission not enabled",
                Toast.LENGTH_LONG).show();

        return;
    }

    if (!fingerprintManager.hasEnrolledFingerprints()) {

        // This happens when no fingerprints are registered.
        Toast.makeText(this, "Register at least one fingerprint in Settings",
                Toast.LENGTH_LONG).show();
        return;
    }

    generateKey();

    if (cipherInit()) {
        cryptoObject = new FingerprintManager.CryptoObject(cipher);
        FingerprintHandler helper = new FingerprintHandler(this);
        helper.startAuth(fingerprintManager,cryptoObject);
    }

}

protected void generateKey() {
    try {
        keyStore = KeyStore.getInstance("AndroidKeyStore");
    } catch (Exception e) {
        e.printStackTrace();
    }

    try {
        keyGenerator = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES,
                "AndroidKeyStore");
    } catch (NoSuchAlgorithmException | NoSuchProviderException e) {
        throw new RuntimeException("Failed to get KeyGenerator instance", e);
    }

    try {
        keyStore.load(null);
        keyGenerator.init(new KeyGenParameterSpec.Builder(KEY_NAME, KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT)
                .setBlockModes(KeyProperties.BLOCK_MODE_CBC)
                .setUserAuthenticationRequired(true)
                .setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_PKCS7)
                .build());
        keyGenerator.generateKey();
    } catch (NoSuchAlgorithmException | InvalidAlgorithmParameterException | CertificateException | IOException e) {
        throw new RuntimeException(e);
    }

}

public boolean cipherInit() {
    try {
        cipher = Cipher.getInstance(KeyProperties.KEY_ALGORITHM_AES + "/" + KeyProperties.BLOCK_MODE_CBC + "/"
                        + KeyProperties.ENCRYPTION_PADDING_PKCS7);
    } catch (NoSuchAlgorithmException | NoSuchPaddingException e) {
        throw new RuntimeException("Failed to get Cipher", e);
    }

    try {
        keyStore.load(null);
        SecretKey key = (SecretKey) keyStore.getKey(KEY_NAME,null);
        cipher.init(Cipher.ENCRYPT_MODE, key);
        return true;
    } catch (KeyPermanentlyInvalidatedException e) {
        return false;
    } catch (KeyStoreException | CertificateException | UnrecoverableKeyException | IOException
            | NoSuchAlgorithmException | InvalidKeyException e) {
        throw new RuntimeException("Failed to init Cipher", e);
    }
}
}

This is FingerprintHandler.java : 这是FingerprintHandler.java:

public class FingerprintHandler extends FingerprintManager.AuthenticationCallback {

private CancellationSignal cancellationSignal;
private Context appContext;


public FingerprintHandler(Context context) {
    appContext = context;}


public void startAuth(FingerprintManager manager, FingerprintManager.CryptoObject cryptoObject) {

    cancellationSignal = new CancellationSignal();

    if (ActivityCompat.checkSelfPermission(appContext, Manifest.permission.USE_FINGERPRINT) !=
            PackageManager.PERMISSION_GRANTED) {
        return;
    }
    manager.authenticate(cryptoObject, cancellationSignal, 0, this, null);
}

@Override
public void onAuthenticationError(int errMsgId,
                                  CharSequence errString) {
    Toast.makeText(appContext,
            "Authentication error\n" + errString,
            Toast.LENGTH_LONG).show();
}

@Override
public void onAuthenticationHelp(int helpMsgId,
                                 CharSequence helpString) {
    Toast.makeText(appContext,
            "Authentication help\n" + helpString,
            Toast.LENGTH_LONG).show();
}

@Override
public void onAuthenticationFailed() {
    Toast.makeText(appContext,
            "Authentication failed.",
            Toast.LENGTH_LONG).show();
}

@Override
public void onAuthenticationSucceeded(
        FingerprintManager.AuthenticationResult result) {

    Toast.makeText(appContext,
            "Authentication succeeded.",
            Toast.LENGTH_LONG).show();


}

}

This is the second layout that I need to move after fingerprint success EmployeeLoginActivity.java : 这是指纹成功EmployeeLoginActivity.java之后我需要移动的第二个布局:

public class EmployeeLoginActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_employee_login);

    }
}

Something like this should work to start the new Activity on a successful authentication: 这样的事情应该可以在成功的身份验证上启动新的Activity

@Override
public void onAuthenticationSucceeded(
        FingerprintManager.AuthenticationResult result) {

    Toast.makeText(appContext,
            "Authentication succeeded.",
            Toast.LENGTH_LONG).show();

    appContext.startActivity(new Intent(appContext,
        EmployeeLoginActivity.class));
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何移动到 Android 中的第二个布局? - How can move to second layout in Android? 适用于Android指纹的Aadhar身份验证RD服务 - Aadhar Authentication RD Service for fingerprint Android Android指纹扫描仪,检测用于身份验证的手指 - Android Fingerprint Scanner, detecting the finger used for authentication 表单认证成功后返回403 - 403 after successful form authentication 在android AsyncTask注册成功后,如何移动类? - How to move the class, when the registration is successful at android AsyncTask? 如何在成功验证后使Spring安全性调用所请求的资源? - How to make spring security to call the requested resource after a successful authentication? 认证成功但授权失败后如何返回HTTP 403? - How to return HTTP 403 after successful authentication, but unsuccessful authorization? 如何使按钮每秒随机在布局中移动 - How to make a Button randomly Move in a Layout every second 如何在不使用android的指纹管理器的情况下创建指纹认证登录? - How can I create a fingerprint authentication login without using android's fingerprintmanager? Android Studio// 尝试打开第二个布局后应用程序崩溃 - Android Studio// App crashes after trying to open second layout
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM