Android implements mailbox validation

Time:2019-10-8

In this paper, we share the specific code of Android to implement mailbox verification function for your reference. The details are as follows.

Target effect:

<

Resource bundle (three jar bundles and two Java pages): Click to open the link

1. First, you need to register a mailbox (as a special mailbox for issuing authentication codes, I am newly registered), and then open the POP3 column in the webpage version;

2. Check both squares:

3. Hint to set authorization code;

4. Disabled by default, click Open:

5. Enter the authorization code promptly. When the input is completed, the form will be displayed. The right side of the form shows that it is not disabled:

6. Mailbox configuration completed

7. Create a new project, import and reference three jar packages in the resource bundle, then add two other Java pages and change part of SendEmail. Java page

8. Activity_, main.xml page:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:app="http://schemas.android.com/apk/res-auto"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:orientation="vertical"
 tools:context="com.example.vico.emailtest.MainActivity">
 
 <EditText
 android:id="@+id/etInputEmail"
 android:layout_width="300dp"
 android:layout_gravity="center_horizontal"
 android:layout_height="wrap_content"
 android:gravity="center"
 Android: hint= "mailbox"
 android:layout_marginTop="100dp"/>
 
 <Button
 android:id="@+id/btGetNum"
 android:layout_width="150dp"
 android:layout_gravity="center_horizontal"
 android:layout_height="wrap_content"
 android:layout_marginTop="20dp"
 android:onClick="btClick"
 Android: text = "Send authentication code" />
 
 <EditText
 android:id="@+id/etInputGetNum"
 android:layout_width="100dp"
 android:layout_gravity="center_horizontal"
 android:layout_height="wrap_content"
 android:gravity="center"
 Android: hint= "authentication code"
 android:layout_marginTop="100dp"/>
 
 <Button
 android:id="@+id/btSubmit"
 android:layout_width="150dp"
 android:layout_gravity="center_horizontal"
 android:layout_height="wrap_content"
 android:layout_marginTop="20dp"
 android:onClick="btClick"
 Android: text = "submit" />
 
</LinearLayout>

9.MainActivity.java:

package com.example.vico.emailtest;
 
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
 
import com.example.vico.other.RandomNumber;
import com.example.vico.other.SendEmail;
 
public class MainActivity extends AppCompatActivity {
 
 private EditText etInputEmail,etInputGetNum;
 
 Private long verificationCode = 0; // Generated validation code
 Private String email; //mailbox
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 
 init();
 }
 
 private void init() {
 etInputEmail= (EditText) findViewById(R.id.etInputEmail);
 etInputGetNum= (EditText) findViewById(R.id.etInputGetNum);
 }
 public void btClick(View view){
 switch (view.getId()){
 case R.id.btGetNum:
 email=etInputEmail.getText().toString();
 Send Verification Code (email);//Send Verification Code
 break;
 case R.id.btSubmit:
 Judge Verification Code (); // Judge whether the input validation code is correct
 break;
 }
 }
 // Send Verification Code
 private void sendVerificationCode(final String email) {
 try {
 new Thread() {
 @Override
 public void run() {
 super.run();
 try {
 RandomNumber rn = new RandomNumber();
 verificationCode = rn.getRandomNumber(6);
 SendEmail se = new SendEmail(email);
 Se.sendHtmlEmail (verification Code);//Send HTML mail
 Toast. makeText (MainActivity. this, "Send Successfully", Toast. LENGTH_LONG). show ();
 } catch (Exception e) {
 e.printStackTrace();
 }
 }
 }.start();
 } catch (Exception e) {
 e.printStackTrace();
 }
 }
 
 // Determine whether the input validation code is correct
 private void judgeVerificationCode() {
 If (Integer. parseInt (etInputGetNum. getText (). toString ()== verificationCode) {// Verification Code and input consistent
 Toast. makeText (MainActivity. this, "Verification Successful", Toast. LENGTH_LONG). show ();
 }else{
 Toast. makeText (MainActivity. this,'Verification Failure', Toast. LENGTH_LONG). show ();
 }
 }
}

10. Add permissions:

<! - Allow networking - >
 <uses-permission android:name="android.permission.INTERNET"/>
 <! - Obtain information about network status such as GSM (2g), WCDMA (Unicom 3g) --> __________.
 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
 <! - Get information about the state of Wifi Network - >
 <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>

Source Download: Click Open Link

The above is the whole content of this article. I hope it will be helpful to everyone’s study, and I hope you will support developpaer more.