In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces Android how to achieve SMS verification service, the article is very detailed, has a certain reference value, interested friends must read it!
The details are 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) }} above are all the contents of the article "how to implement SMS Verification Service in Android". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow 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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.