【问题标题】:Safely store/modify/delete a string in Android在 Android 中安全地存储/修改/删除字符串
【发布时间】:2016-04-20 18:47:15
【问题描述】:

我正在制作一个项目,我需要在我的应用程序中存储一个特定的字符串。我必须能够在用户验证后的任何给定时间存储、删除和修改它,这是通过使用指纹 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();
    }
}

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

【问题讨论】:

    标签: java android android-studio


    【解决方案1】:

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

    【讨论】:

    • 我赞成您的回答,但是您应该稍微完善一下。链接到官方文档的适当部分将是很好的补充。
    【解决方案2】:

    正如@ADM 所说,使用SharedPreference 来存储您的字符串。您可以指定您的数据是私有的还是公开的。

    使用 0 或 MODE_PRIVATE 进行默认操作,使用 MODE_WORLD_READABLE 和 MODE_WORLD_WRITEABLE 来控制权限。

    看看docs 或这个答案here

    在您的情况下,您可以使特定活动(操作您的字符串)只能通过指纹身份验证访问。

    您应该知道,并非所有设备都兼容。

    【讨论】:

    • 是的,整个应用程序都是指纹锁定的,主要是为了确保添加到android系统的新指纹无法解锁这个字符串。不管用户保存多少,我是否可以说“我只希望这个指纹能够解锁我的应用程序”?
    • 我不确定您现在是否可以使用 Android 指纹 API 来执行此操作(您无权访问指纹)。三星指纹 API “更”灵活,给你一个想法img-developer.samsung.com/onlinedocs/sms/pass/index.html
    猜你喜欢
    • 2016-08-21
    • 2022-11-11
    • 2011-07-24
    • 2015-02-03
    • 2021-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多