In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
Today, the editor will share with you the relevant knowledge points about how to achieve SMS verification service in Android. The content is detailed and the logic is clear. I believe most people still know too much about this, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.
The specific code is as follows
Package com.skiers.demo_learn;import android.os.Bundle;import android.os.Handler;import android.os.Looper;import android.os.Message;import android.view.View;import android.widget.EditText;import android.widget.TextView;import com.mob.MobSDK;import androidx.annotation.Nullable;import androidx.appcompat.app.AppCompatActivity;import cn.smssdk.EventHandler;import cn.smssdk.SMSSDK;public class ThridActivity extends AppCompatActivity {EditText editText; TextView textView; EditText editText1; Handler handler; EventHandler eventHandler = null @ Override protected void onCreate (@ Nullable Bundle savedInstanceState) {super.onCreate (savedInstanceState); setContentView (R.layout.activity_third); initView (); initEvent ();} private void initView () {MobSDK.init (this); editText = findViewById (R.id.editText); textView = findViewById (R.id.textView6); editText1 = findViewById (R.id.editText1); SMSSDK.setAskPermisionOnReadContact (false) EventHandler = new EventHandler () {public void beforeEvent (int var1, Object var2) {System.out.println ("beforeEvent + = ="); System.out.println (var1); System.out.println (var2);} public void afterEvent (int event, int result, Object data) {System.out.println ("afterEvent + = =") / / afterEvent will be called in the child thread, so if there is a UI-related operation later, you need to send the data to the UI thread Message msg = new Message (); msg.arg1 = event; msg.arg2 = result; msg.obj = data; getHandler (). SendMessage (msg); System.out.println ("afterEventEND + = ="); System.out.println (data) } public void onRegister () {System.out.println ("onRegister + = =");} public void onUnregister () {System.out.println ("onUnregister + = =");}}; / / register an event callback to process the result SMSSDK.registerEventHandler (eventHandler) of the SMSSDK API request } private void initEvent () {/ / request verification code findViewById (R.id.button) .setOnClickListener (new View.OnClickListener () {@ Override public void onClick (View v) {getHandler () .sendEmptyMessage (- 1); String content = editText.getText () .toString () System.out.println (content + "--edit Text"); / / request verification code, where country represents the country code, such as "86" Phone indicates the mobile phone number, such as "13800138000" SMSSDK.getVerificationCode ("86", content);}}); / / submit the verification code findViewById (R.id.button1) .setOnClickListener (new View.OnClickListener () {@ Override public void onClick (View v) {String content = editText1.getText (). ToString ()) System.out.println (content + "--edit Text"); / / submit CAPTCHA, where code represents CAPTCHA, such as "1357" SMSSDK.submitVerificationCode ("86", "18079919252", content);}}) } / / processing data verification code, mobile phone number-main thread-can Handler with the new view, data processing class private Handler getHandler () {if (handler = = null) {handler = new Handler (Looper.getMainLooper (), new Handler.Callback () {@ Override public boolean handleMessage (Message msg) {int event = msg.arg1; int result = msg.arg2) Object data = msg.obj; if (event = = SMSSDK.EVENT_GET_VERIFICATION_CODE) {if (result = = SMSSDK.RESULT_COMPLETE) {System.out.println ("CAPTCHA has been sent, please check-=") / / the result of the verification code was successfully obtained by TODO processing / / Please note that only the request for sending the verification code has been completed at this time, and it will take a few seconds for the verification code message to be delivered to} else {System.out.println ("failed to send the verification code-=") / / result of TODO handling error ((Throwable) data) .printStackTrace ();} else if (event = = SMSSDK.EVENT_SUBMIT_VERIFICATION_CODE) {if (result = = SMSSDK.RESULT_COMPLETE) {System.out.println ("CAPTCHA passes verification-= =") / / TODO processing the result of verification code verification} else {System.out.println ("verification code failed verification-= ="); / / result of TODO handling error ((Throwable) data) .printStackTrace (); System.out.println ("hello java = =") The return results of other APIs of}} / / TODO are similar. Determine which interface the current data belongs to according to event return false;}});} return handler;} / / you need to log out after using EventHandler, otherwise memory leakage may occur: protected void onDestroy () {super.onDestroy (); SMSSDK.unregisterEventHandler (eventHandler) }} these are all the contents of the article "how to implement SMS Verification Service in Android". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.