【问题标题】:simple password protect your android application简单的密码保护您的 android 应用程序
【发布时间】:2012-02-21 01:38:13
【问题描述】:

我是安卓开发的新手。 我想创建一个简单的受密码保护的应用程序,它在启动时要求输入密码。登录对话框应该只要求输入密码或退出。而已!如果密码输入正确,则应启动应用程序,否则应要求用户再次输入密码并给出退出选项。

欢迎从头开始回答所有细节。

【问题讨论】:

    标签: android passwords protected


    【解决方案1】:

    按照以下步骤操作:

    1. 制作一个单独的Activity,在其onCreate中,弹出一个Alert Dialogue。
    2. 如果密码正确,则仅使用 Intent 开始您的活动。
    3. else finish() 当前活动。
    4. 您可以将密码保存在数据库中或 SharedPreferences 中。

    5. 参考互联网以使用数据库或 SharedPreferences。

    例如 SharedPreferences:

        SharedPreferences mySharedPreferences;
            SharedPreferences.Editor myEditor;
                mySharedPreferences = getSharedPreferences("usernamepassworddetails", MODE_PRIVATE);
            myEditor = mySharedPreferences.edit();
            myEditor.commit();
    
    //In this code you can add the details
    
    
    myEditor.putInt("username", imageWidth);
           myEditor.putInt("password", imageHeight);
           myEditor.putInt("position", currentPosition);
           myEditor.commit();
    

    //获取数据的代码

    mySharedPreferences.getInt("username", 0)
    mySharedPreferences.getInt("password", 0)
    

    数据库相关代码参考此链接: http://www.vogella.de/articles/AndroidSQLite/article.html

    如果有任何帮助,请告诉我。

    【讨论】:

    • 感谢您的回答。实际上,我是通过 Google 进来寻找一种密码保护某个活动的方法,而您的回答为我指明了正确的方向。
    猜你喜欢
    • 2012-03-10
    • 1970-01-01
    • 2019-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-26
    • 1970-01-01
    • 2011-02-22
    相关资源
    最近更新 更多