Android SDK API
SDK API Description
Important notice: The client SDK for Jiguang SMS is no longer updated or maintained. Developers should use the REST API to implement business logic.
SMSSDKclass: the external class. This class is a singleton. To call methods of this class, obtain its unique instance throughSMSSDK.getInstance().SmscodeListener: callback interface for obtaining verification codes. An interface instance must be passed when callingSMSSDK'sgetSmsCode.SmscheckListener: callback interface for checking verification codes. An interface instance must be passed when callingSMSSDK'scheckSmsCode.
Initialization API
API Description
This is the initialization API. It mainly checks configuration information. If the configuration is incorrect, initialization will fail and error logs will be printed. This API must be called before calling other APIs, and it only needs to be called once. It is recommended to call it in Application or the initial Activity.
SMSSDK.initSdk(Context context)
Call Example
SMSSDK.getInstance().initSdk(this);
Obtain SMS Verification Code
API Description
SMSSDK.getSmsCode(String phone, String tempId, SmscodeListener listener)
This API calls back on a non-UI thread. If a UI-thread callback is required, call
SMSSDK.getSmsCodeAsyn().
Parameters
- phone: phone number
- tempId: SMS template
- listener: callback interface
Call Example
SMSSDK.getInstance().getSmsCodeAsyn("159xxxxxxxx", "1", new SmscodeListener() {
@Override
public void getCodeSuccess(final String uuid) {
// Verification code obtained successfully. uuid is the unique identifier for this request.
}
@Override
public void getCodeFail(int errCode, final String errMsg) {
// Failed to obtain verification code. errCode is the error code. See the error code table later in this document for details. errMsg is the error description.
}
});
Verify SMS Verification Code
API Description
SMSSDK.checkSmsCode(String phone, String code, SmscheckListener listener)
This API calls back on a non-UI thread. If a UI-thread callback is required, call
SMSSDK.checkSmsCodeAsyn().
Parameters
- phone: phone number
- code: SMS verification code
- listener: callback interface
Call Example
SMSSDK.getInstance().checkSmsCodeAsyn("159xxxxxxxx", "123456", new SmscheckListener() {
@Override
public void checkCodeSuccess(final String code) {
// Verification code verified successfully. code is the verification code information.
}
@Override
public void checkCodeFail(int errCode, final String errMsg) {
// Verification code verification failed. errCode is the error code. See the error code table later in this document for details. errMsg is the error description.
}
});
Obtain Voice Verification Code (Chinese)
API Description
Obtain a voice verification code. The voice language is Chinese.
SMSSDK.getVoiceCode(String phone, SmscodeListener listener)
This API calls back on a non-UI thread. If a UI-thread callback is required, call
SMSSDK.getVoiceCodeAsyn().
Parameters
- phone: phone number
- listener: callback interface
Call Example
SMSSDK.getInstance().getVoiceCodeAsyn("159xxxxxxxx", new SmscodeListener() {
@Override
public void getCodeSuccess(final String uuid) { // Verification code obtained successfully. uuid is the unique identifier for this request. } @Override public void getCodeFail(int errCode, final String errMsg) { // Failed to obtain verification code. errCode is the error code. See the error code table later in this document for details. errMsg is the error description. } });
Obtain Voice Verification Code (Other Languages)
API Description
Obtain a voice verification code. This API allows the language to be specified.
SMSSDK.getVoiceCode(String phone,int language,SmscodeListener listener)
This API calls back on a non-UI thread. If a UI-thread callback is required, call
SMSSDK.getVoiceCodeAsyn().
Parameters
- phone: phone number
- language: 0 for Chinese, 1 for English, 2 for Chinese and English. Passing an unsupported language returns error 50040.
- listener: callback interface
Call Example
SMSSDK.getInstance().getVoiceCodeAsyn("159xxxxxxxx",2,new SmscodeListener() {
@Override
public void getCodeSuccess(final String uuid) { // Verification code obtained successfully. uuid is the unique identifier for this request. } @Override public void getCodeFail(int errCode, final String errMsg) { // Failed to obtain verification code. errCode is the error code. See the error code table later in this document for details. errMsg is the error description. } });
Set the Interval for Obtaining Verification Codes
API Description
Set the interval between two verification code requests. The default is 30 seconds.
SMSSDK.setIntervalTime(long intervalTime)
Parameters
- intervalTime: interval time, in milliseconds (ms).
Call Example
SMSSDK.getInstance().setIntervalTime(60000); // Set the interval to 60 seconds
Obtain the Current Interval Setting
API Description
Obtain the current interval setting.
SMSSDK.getIntervalTime()
Return Value
- long: in milliseconds (ms).
Call Example
SMSSDK.getInstance().getIntervalTime();
Set Debug Mode
API Description
Set debug mode. Setting it to true outputs SDK logs.
SMSSDK.setDebugMode(boolean debugMode)
Parameters
- debugMode: true for debug mode, false for non-debug mode.
Call Example
SMSSDK.getInstance().setDebugMode(true);
Error Code Description
Error Code |
Description |
Remarks |
|---|---|---|
| 3001 | Request timeout | |
| 3002 | Invalid phone number | |
| 4001 | Body is empty | |
| 4002 | Invalid AppKey | |
| 4003 | Invalid source | |
| 4004 | Body decryption failed | |
| 4005 | AES key decryption failed | |
| 4006 | Timestamp conversion failed | |
| 4007 | Incorrect body format | |
| 4008 | Invalid timestamp | |
| 4009 | No SMS verification permission | |
| 4011 | Sending too frequent | The same phone number has no daily limit for obtaining verification codes. Notification messages with the same content are limited to 3 messages per 10 minutes; different content is unlimited. Marketing messages are limited to 3 messages per 10 minutes. |
| 4013 | Template does not exist | |
| 4014 | extra is empty | |
| 4015 | Verification code is incorrect | |
| 4016 | No balance | |
| 4017 | Verification code timed out | |
| 4018 | Duplicate verification | |
| 2993 | Verification code check failed | SMS was delivered but uuid retrieval exception occurred |
| 2994 | Local data error | |
| 2995 | Data parsing error | |
| 2996 | Two requests are no more than 1 minute apart | Local validation |
| 2997 | Verification code not obtained | |
| 2998 | Network error | No network, etc. |
| 2999 | Other error | |
| 50040 | Unsupported language passed | 0 for Chinese, 1 for English, 2 for Chinese and English |