Obtain the verification code using Android
The simple function is to define a CountDownTimer to directly view the code.
First, put a button code in XML as follows:
The following is the main code:
Package com. example. countdowntimer; import android. OS. bundle; import android. OS. countDownTimer; import android. app. activity; import android. graphics. color; import android. view. menu; import android. view. view; import android. view. view. onClickListener; import android. widget. button; public class MainActivity extends Activity {private TimeCount time; private Button btnGetcode; @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); time = new TimeCount (60000,100 0); btnGetcode = (Button) findViewById (R. id. btn_getcode); btnGetcode. setOnClickListener (new OnClickListener () {@ Overridepublic void onClick (View v) {time. start () ;}});} class TimeCount extends CountDownTimer {public TimeCount (long millisInFuture, long countDownInterval) {super (millisInFuture, countDownInterval);} @ Overridepublic void onTick (long timer) {btnGetcode. setBackgroundColor (Color. parseColor (# B6B6D8); btnGetcode. setClickable (false); btnGetcode. setText (millisUntilFinished/1000 + seconds later);} @ Overridepublic void onFinish () {btnGetcode. setText (re-obtain the Verification Code); btnGetcode. setClickable (true); btnGetcode. setBackgroundColor (Color. parseColor (# 4EB84A ));}}}