这是我使用的函数的代码:
public void redirecttohome() {
//variable init
edtpass = (EditText) findViewById(R.id.edtpass);
edtuserid = (EditText) findViewById(R.id.edtuserid);
String text="";
try {
InputStream is = getAssets().open("login.txt");
int size = is.available();
byte [] buffer = new byte[size];
is.read(buffer);
text = new String (buffer);
if (edtuserid.getText().toString().equals(text) && edtpass.getText().toString().equals(text)) {
startActivity(new Intent(getApplicationContext(), MainActivity.class));
}
else {Snackbar.make(parent_view, "Invalid UserID and Password", Snackbar.LENGTH_SHORT).show();}
is.close();
} catch (IOException e) {
Log.e("Error!", "Error occured while reading text file from Internal Storage!");
}
}
我想从保存在资产目录中的文本中检查用户 ID 和密码,并重定向到家庭活动。
慕仙森
相关分类