am试图集成Quick Email Verification API以在用户输入真实电子邮件地址时对其进行验证。因此,请遵循其文档和示例代码。在我添加他们的验证代码段之前,我的应用程序运行良好。现在,在我按下注册按钮后,它就停止工作了。 编码是新手,我知道错误在哪里。帮助赞赏! TIA!
这是我的btn_register代码:
btn_register.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String username = et_username.getText().toString();
String password = et_password.getText().toString();
String confirm_password = et_cpassword.getText().toString();
String email = et_email.getText().toString();
String mobile = et_mobile.getText().toString();
if (username.equals("") || password.equals("") || confirm_password.equals("") ||
email.isEmpty() || mobile.isEmpty()) {
Toast.makeText(getApplicationContext(), "Fields Required",
Toast.LENGTH_SHORT).show();
} else if (!isValidEmail(et_email.getText().toString())) {
Toast.makeText(getApplicationContext(), "Email is not valid",
Toast.LENGTH_SHORT).show();
} else if (!password.equals(confirm_password)) {
Toast.makeText(getApplicationContext(), "Password does not match",
Toast.LENGTH_SHORT).show();
} else if (!isValidNumber(et_mobile.getText().toString())) {
Toast.makeText(getApplicationContext(), "Input valid number",
Toast.LENGTH_SHORT).show();
}
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent);
Toast.makeText(getApplicationContext(), "User registered", Toast.LENGTH_SHORT).show();
insertUser();
}
private boolean isValidEmail(String email) {
try {
new QevSingleAPI().http.sendGet();
} catch (Exception e) {
e.printStackTrace();
}
return Boolean.parseBoolean(email);
}
private boolean isValidNumber(String mobile) {
return Patterns.PHONE.matcher(mobile).matches();
}
});
}
这是Qev类:
public class QevSingleAPI extends Registration {
QevSingleAPI http = new QevSingleAPI();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_registration);
try {
http.sendGet();
} catch (Exception e) {
e.printStackTrace();
}
}
void sendGet() throws Exception {
String API_KEY = "apiKey";
String EMAIL = et_email.getText().toString();
String url = "http://api.quickemailverification.com/v1/verify?email="+EMAIL+"&apikey="+API_KEY;
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
// optional default is GET
con.setRequestMethod("GET");
int responseCode = con.getResponseCode();
System.out.println("\nSending 'GET' request to URL : " + url);
System.out.println("Response Code : " + responseCode);
BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuilder response = new StringBuilder();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
Toast.makeText(getApplicationContext(), response.toString(), Toast.LENGTH_SHORT).show();
}
}