gpt4 book ai didi

java - 在 Android 中安全地存储/修改/删除字符串

转载 作者:行者123 更新时间:2023-11-29 19:55:41 25 4
gpt4 key购买 nike

我正在制作一个项目,我需要在我的应用程序中存储一个特定的字符串。我必须能够在用户通过身份验证后的任何给定时间存储、删除和修改它,这是通过使用指纹 API 完成的。

如果可能,我想确保只有选定的指纹,或只有在添加此字符串之前手机中的指纹才能解锁/显示此字符串

例如,我想在其中检查密码的弹出窗口如下:

package com.gmtechnology.smartalarm;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;

public class Check_Pass extends DialogFragment {

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
// Get the layout inflater
LayoutInflater inflater = getActivity().getLayoutInflater();

// Inflate and set the layout for the dialog
// Pass null as the parent view because its going in the dialog layout
builder.setView(inflater.inflate(R.layout.check_pass, null))
// Add action buttons
.setPositiveButton(R.string.check, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
//Check if the entered string matches the string stored
DialogFragment next = new Add_Pass();
next.show(getFragmentManager(), "Add_pass");

}
})
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Check_Pass.this.getDialog().cancel();
}
});
return builder.create();
}
}

这个弹出窗口有一个编辑文本,我可以从中捕获输入以用于比较,添加和删除将遵循相同的模式。这里的要点以及如何安全地存储和管理该字符串。

最佳答案

安全存储什么??看看你是否想要持久存储,即即使在你的应用程序关闭后你也需要保存它。那么你应该使用 Shared Preference ..它非常易于使用和修改。或者,如果您只想在应用程序运行时保存它一次,那么只需为它使用一个单例类 ..

关于java - 在 Android 中安全地存储/修改/删除字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36752559/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com