Je suis nouveau sur android.J'ai simplement un champ de texte où l'utilisateur entre leur adresse e-mail.J'ai une liste de courrier électronique vérifié à mon backend.Maintenant, quand l'utilisateur entre email.Je devrais vérifiez d'abord si le courrier électronique est vérifié en backend ou non. Si l'email est vérifié, l'utilisateur a accès à l'activité suivante sinon.Comment vérifier email à partir du serveur
public class Ongoing extends Fragment {
Button proceed;
EditText email;
TextView surveyTitle;
String success;
private static final String url="http://192.168.0.123/survey/public/api/verifyemail";
public Ongoing() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View v=inflater.inflate(R.layout.fragment_ongoing, container, false);
surveyTitle= (TextView) v.findViewById(R.id.surveyTitle);
email = (EditText) v.findViewById(R.id.email);
proceed= (Button) v.findViewById(R.id.proceed);
proceed.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(isConnected()) {
String emailAddress = email.getText().toString().trim();
String emailPattern = "[a-zA-Z0-9._-][email protected][a-z]+\\.+[a-z]+";
if (emailAddress.matches("")) {
Toast.makeText(getContext(), "Please fill up all the fields", Toast.LENGTH_LONG).show();
} else {
if (emailAddress.matches(emailPattern)) {
new HttpAsyncTask().execute("http://192.168.0.123/survey/public/api/verifyemail");
} else
Toast.makeText(getContext(), "Invalid Email Address", Toast.LENGTH_LONG).show();
}
}
else {
Toast.makeText(getContext(), "Please check your internet connection", Toast.LENGTH_LONG).show();
}
}
});
return v;
}
private class HttpAsyncTask extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... urls) {
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("email", email.getText().toString()));
JSONParser jParser = new JSONParser();
JSONObject json = jParser.makeHttpRequest(url, "POST", params);
try {
success = json.getString("success");
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String result) {
if(success.equals("Email verified. Please proceed with survey"))
Toast.makeText(getContext(), "Wait For a moment", Toast.LENGTH_LONG).show();
}
}
public boolean isConnected(){
ConnectivityManager connMgr = (ConnectivityManager) getActivity().getSystemService(Activity.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
if (networkInfo != null && networkInfo.isConnected())
return true;
else
return false;
}
}
Quelqu'un s'il vous plaît aidez-moi.
Quel est votre problème/erreur? –
@Robin aucune erreur ou solution –