Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/183.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android应用Beta版的密码系统_Java_Android_Debugging - Fatal编程技术网

Java Android应用Beta版的密码系统

Java Android应用Beta版的密码系统,java,android,debugging,Java,Android,Debugging,在过去的几天里,我一直在开发我的第一个android应用程序,我终于进入了测试阶段。我和我的一些朋友很快就会尝试正确的应用程序,因为它应该被使用 我已经尝试实现了一个密码系统,这样,如果程序在测试期间泄漏,其他测试人员将无法使用它。为了做到这一点,我做了一个算法,我想这就是他们所说的算法,它会根据一年中的周数生成一个密码。这并不复杂,但我怀疑我认识的任何人都能破解它 无论如何,这个活动是清单中的.LAUNCHER和.MAIN,我正在为Android 2.1 API 7开发。加载时,它会创建一个e

在过去的几天里,我一直在开发我的第一个android应用程序,我终于进入了测试阶段。我和我的一些朋友很快就会尝试正确的应用程序,因为它应该被使用

我已经尝试实现了一个密码系统,这样,如果程序在测试期间泄漏,其他测试人员将无法使用它。为了做到这一点,我做了一个算法,我想这就是他们所说的算法,它会根据一年中的周数生成一个密码。这并不复杂,但我怀疑我认识的任何人都能破解它

无论如何,这个活动是清单中的.LAUNCHER和.MAIN,我正在为Android 2.1 API 7开发。加载时,它会创建一个editText和一个按钮。基本上,当按下按钮且editText等于算法的答案时,应打开主应用程序。但它不起作用

我在eclipse中使用了调试工具来检查所有变量是否正确,它们都是正确的,但它不想工作。谁能帮我一下吗。我的密码是贝娄

import java.util.Calendar;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.GetChars;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class ContactActivity extends Activity {
    EditText Code; // prepare xml stuff
    Button Go;

    int Turns = 3; // turns in total

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.checkcode);

        Go = (Button) findViewById(R.id.bGo); // link go button
        Code = (EditText) findViewById(R.id.etCode); // link code to text box

        Go.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                String UserCode = (String)Code.getText().toString();
                int WeekNo = Calendar.WEEK_OF_YEAR;
                int Algorithm = WeekNo * 123 + WeekNo;
                String Answer = Integer.toString(Algorithm);

                if(UserCode == Answer){
                    Intent beginContact = new Intent("com.URS.Kalashnikov.MAINPAGE"); // set intent to switch to 
                    // main activity
                    startActivity(beginContact); // start activity
                } else {
                    Turns -= 1; // remove turns by one

                    if(Turns <= 0){
                        Context context = getApplicationContext();
                        CharSequence text = "Incorrect Code. No chances left";
                        // text for the toast
                        int duration = Toast.LENGTH_LONG; // toast length

                        Toast warning = Toast.makeText(context, text, duration); // prepare a toast
                        warning.show(); // show the toast

                        finish(); // kill the program if there is zero turns left
                    } else {
                        Code.setText("");

                        // make a toast
                        Context context = getApplicationContext();
                        CharSequence text = "Incorrect Code - Please try again. You have " + Turns + " chances left";
                        // text for the toast
                        int duration = Toast.LENGTH_LONG; // toast length

                        Toast warning = Toast.makeText(context, text, duration); // prepare a toast
                        warning.show(); // show the toast
                    }
                }
            }

        });
    }
}

在我的代码中有一些我没有提到的额外内容,但您可能会找到答案。

只有当UserCode==test时,您才能启动活动。您的代码片段似乎是硬编码的。尝试在编辑框中输入测试。你的活动启动了吗

编辑:

试试这个:

Intent beginContact = new Intent(this, YouActivity.class);`

实际上,Java中的UserCode==Answer并不比较两个字符串,而是比较两个对象。在你的情况下,他们永远不会平等。改用UserCode.equalsignorecasesAnswer或UserCode.equalsAnswer

为什么不干脆把.apk交给你的测试人员,让他们不要泄露呢?如果你不相信他们不会泄露程序本身,为什么你会相信他们不会泄露密码呢?因为密码每周都会自动改变。这就是为什么它是基于一年中的一周。简单地说,如果被泄露,我不会给任何人密码,或者我会给我信任的人。这并不意味着泄露它,因为你将无法再访问它,或者只需在apk上使用过期密码,跳过所有密码,或者将其添加到市场中,然后使用许可证,只将其电子邮件地址放入测试框。好的,如果你这么说的话。请详细说明它不想工作-到底发生了什么?看看你的代码,至少你应该用int-WeekNo=Calendar.getInstance.getCalendar.WEEK\u OF theu YEAR替换int-WeekNo=Calendar.getInstance.getCalendar.WEEK\u OF theu YEAR,用if-Answer.equalsUserCode替换ifUserCode==test。我已经试过了——它不起作用。我感觉可能是在声明用户代码的地方,但我不知道那里怎么会有错误。当我上传代码的时候,我忘了把它去掉……或者可能是你用==而不是等于来比较字符串。到底有什么区别。我以前用C++编程,所以我只是用= =看。这是引用比较和内容比较——差别很大。UserCode==答案肯定是错误的,但您应该能够在调试时看到这一点。你不觉得吗?