需要单独申请 短信验证码的key才可以使用 https://www.juhe.cn/docs
package com.juhe.captcha;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.Html;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import com.thinkland.sdk.sms.SMSCaptcha;
import com.thinkland.sdk.util.BaseData.ResultCallBack;
public class CaptchaActivity extends BaseActivity implements OnClickListener,
TextWatcher {
private final String tag = "CaptchaActivity";
private static final int RETRY_INTERVAL = 60;
private String phone;
private String formatedPhone;
private int time = RETRY_INTERVAL;
private EditText etIdentifyNum;
private TextView tvTitle;
private TextView tvPhone;
private TextView tvIdentifyNotify;
private TextView tvUnreceiveIdentify;
private ImageView ivClear;
private Button btnSubmit;
private SMSCaptcha smsCaptcha;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_captcha);
smsCaptcha = SMSCaptcha.getInstance();
Intent intent = getIntent();
this.formatedPhone = intent.getStringExtra("formatedPhone");
this.phone = intent.getStringExtra("phone");
btnSubmit = (Button) this.findViewById(R.id.btn_submit);
btnSubmit.setOnClickListener(this);
btnSubmit.setEnabled(false);
tvTitle = (TextView) this.findViewById(R.id.tv_title);
tvTitle.setText(R.string.smssdk_write_identify_code);
etIdentifyNum = (EditText) findViewById(R.id.et_put_identify);
etIdentifyNum.addTextChangedListener(this);
tvIdentifyNotify = (TextView) findViewById(R.id.tv_identify_notify);
String text = getResources().getString(
R.string.smssdk_send_mobile_detail);
tvIdentifyNotify.setText(Html.fromHtml(text));
tvPhone = (TextView) findViewById(R.id.tv_phone);
tvPhone.setText(formatedPhone);
tvUnreceiveIdentify = (TextView) findViewById(R.id.tv_unreceive_identify);
String unReceive = getResources().getString(
R.string.smssdk_receive_msg, time);
tvUnreceiveIdentify.setText(Html.fromHtml(unReceive));
tvUnreceiveIdentify.setOnClickListener(this);
tvUnreceiveIdentify.setEnabled(false);
ivClear = (ImageView) findViewById(R.id.iv_clear);
ivClear.setOnClickListener(this);
countDown();
}
private void countDown() {
new Thread(new Runnable() {
@Override
public void run() {
while (time-- > 0) {
String unReceive = CaptchaActivity.this.getResources()
.getString(R.string.smssdk_receive_msg, time);
updateTvUnreceive(unReceive);
Log.i("time is about ", unReceive);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
String unReceive = getResources().getString(
R.string.smssdk_unreceive_identify_code, time);
updateTvUnreceive(unReceive);
time = RETRY_INTERVAL;
}
}).start();
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO
if (s.length() > 0) {
btnSubmit.setEnabled(true);
ivClear.setVisibility(View.VISIBLE);
btnSubmit.setBackgroundResource(R.drawable.smssdk_btn_enable);
} else {
btnSubmit.setEnabled(false);
ivClear.setVisibility(View.GONE);
btnSubmit.setBackgroundResource(R.drawable.smssdk_btn_disenable);
}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void afterTextChanged(Editable s) {
}
@Override
public void onClick(View v) {
int id = v.getId();
if (id == R.id.btn_submit) {
//
showDialog();
String captcha = etIdentifyNum.getText().toString().trim();
smsCaptcha.commitCaptcha(phone, captcha, new ResultCallBack() {
@Override
public void onResult(int code, String reason, String result) {
// TODO Auto-generated method stub
closeDialog();
Log.v(tag, "code:" code ";reason:" reason);
showToast(reason);
if (code == 0) {
finish();
}
}
});
} else if (id == R.id.tv_unreceive_identify) {
//
showDialog();
} else if (id == R.id.iv_clear) {
//
etIdentifyNum.getText().clear();
}
}
//
private void showDialog() {
String strContent = getResources().getString(
R.string.smssdk_resend_identify_code);
AlertDialog.Builder builder = new AlertDialog.Builder(
CaptchaActivity.this);
builder.setTitle("SMSSDK Demo")
.setIcon(R.drawable.ic_launcher)
.setCancelable(false)
.setMessage(strContent)
.setPositiveButton(R.string.smssdk_ok,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
showDialog(getResources()
.getString(
R.string.smssdk_get_verification_code_content));
smsCaptcha.sendCaptcha(phone.trim(),
new ResultCallBack() {
@Override
public void onResult(int code,
String reason, String result) {
// TODO Auto-generated method
// stub
closeDialog();
Log.v(tag, "code:" code
";reason:" reason);
}
});
}
})
.setNegativeButton(R.string.smssdk_back,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
dialog.dismiss();
finish();
}
});
}
private void showNotifyDialog() {
String strContent = this.getResources().getString(
R.string.smssdk_close_identify_page_dialog);
AlertDialog.Builder builder = new AlertDialog.Builder(
CaptchaActivity.this);
builder.setTitle("Captcha Demo")
.setIcon(R.drawable.ic_launcher)
.setCancelable(false)
.setMessage(strContent)
.setPositiveButton(R.string.smssdk_wait,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
dialog.dismiss();
}
})
.setNegativeButton(R.string.smssdk_back,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
dialog.dismiss();
finish();
}
});
builder.create().show();
}
@Override
public void onBackPressed() {
// TODO Auto-generated method stub
showNotifyDialog();
}
private void updateTvUnreceive(final String unReceive) {
runOnUiThread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
tvUnreceiveIdentify.setText(Html.fromHtml(unReceive));
tvUnreceiveIdentify.setEnabled(false);
}
});
}
}
资源文件列表
Captcha/.classpath , 475
Captcha/.DS_Store , 6148
Captcha/.project , 843
Captcha/.settings/org.eclipse.jdt.core.prefs , 177
Captcha/AndroidManifest.xml , 1742
Captcha/bin/AndroidManifest.xml , 1742
Captcha/bin/Captcha.apk , 329067
Captcha/bin/classes.dex , 1112100
Captcha/bin/classes/com/juhe/captcha/BaseActivity.class , 1600
Captcha/bin/classes/com/juhe/captcha/BuildConfig.class , 341
Captcha/bin/classes/com/juhe/captcha/CaptchaActivity$1.class , 1645
Captcha/bin/classes/com/juhe/captcha/CaptchaActivity$2.class , 1371
Captcha/bin/classes/com/juhe/captcha/CaptchaActivity$3$1.class , 1452
Captcha/bin/classes/com/juhe/captcha/CaptchaActivity$3.class , 1815
Captcha/bin/classes/com/juhe/captcha/CaptchaActivity$4.class , 898
Captcha/bin/classes/com/juhe/captcha/CaptchaActivity$5.class , 874
Captcha/bin/classes/com/juhe/captcha/CaptchaActivity$6.class , 904
Captcha/bin/classes/com/juhe/captcha/CaptchaActivity$7.class , 1053
Captcha/bin/classes/com/juhe/captcha/CaptchaActivity.class , 7113
Captcha/bin/classes/com/juhe/captcha/CaptchaApplication.class , 575
Captcha/bin/classes/com/juhe/captcha/R$attr.class , 334
Captcha/bin/classes/com/juhe/captcha/R$drawable.class , 894
Captcha/bin/classes/com/juhe/captcha/R$id.class , 712
Captcha/bin/classes/com/juhe/captcha/R$layout.class , 484
Captcha/bin/classes/com/juhe/captcha/R$string.class , 1147
Captcha/bin/classes/com/juhe/captcha/R$style.class , 425
Captcha/bin/classes/com/juhe/captcha/R.class , 563
Captcha/bin/classes/com/juhe/captcha/RegisterActivity$1$1.class , 1184
Captcha/bin/classes/com/juhe/captcha/RegisterActivity$1.class , 1785
Captcha/bin/classes/com/juhe/captcha/RegisterActivity$2.class , 916
Captcha/bin/classes/com/juhe/captcha/RegisterActivity.class , 6684
Captcha/bin/dexedLibs/android-support-v4-7dee92d473a431929ce7a364ae4d60da.jar , 273788
Captcha/bin/dexedLibs/smscaptcha_v_1_4-e50b6fdb22fa469315a9e8bdd9e2a315.jar , 11560
Captcha/bin/jarlist.cache , 120
Captcha/bin/resources.ap_ , 23405
Captcha/bin/res/crunch/drawable-hdpi/ic_launcher.png , 1393
Captcha/bin/res/crunch/drawable-mdpi/ic_launcher.png , 1393
Captcha/bin/res/crunch/drawable-xhdpi/ic_launcher.png , 1393
Captcha/bin/res/crunch/drawable-xhdpi/smssdk_clear_search.png , 649
Captcha/bin/res/crunch/drawable-xhdpi/smssdk_cl_divider.png , 67
Captcha/bin/res/crunch/drawable-xhdpi/smssdk_dialog_back.9.png , 716
Captcha/bin/res/crunch/drawable-xhdpi/smssdk_dialog_bg.9.png , 716
Captcha/bin/res/crunch/drawable-xhdpi/smssdk_input_bg_focus.9.png , 271
Captcha/bin/res/crunch/drawable-xhdpi/smssdk_input_bg_normal.9.png , 261
Captcha/bin/res/crunch/drawable-xhdpi/smssdk_input_bg_special_focus.9.png , 259
Captcha/bin/res/crunch/drawable-xhdpi/smssdk_input_bg_special_normal.9.png , 256
Captcha/bin/res/crunch/drawable-xhdpi/smssdk_sharesdk_icon.png , 2434
Captcha/bin/res/crunch/drawable-xxhdpi/ic_launcher.png , 1393
Captcha/gen/com/juhe/captcha/BuildConfig.java , 158
Captcha/gen/com/juhe/captcha/R.java , 4345
Captcha/ic_launcher-web.png , 1259
Captcha/libs/android-support-v4.jar , 758727
Captcha/libs/armeabi/libSMSSDK_v_1_1.so , 22732
Captcha/libs/smscaptcha_v_1_4.jar , 22639
Captcha/lint.xml , 370
Captcha/proguard-project.txt , 781
Captcha/project.properties , 563
Captcha/res/drawable-hdpi/ic_launcher.png , 1259
Captcha/res/drawable-mdpi/ic_launcher.png , 1259
Captcha/res/drawable-xhdpi/ic_launcher.png , 1259
Captcha/res/drawable-xhdpi/smssdk_clear_search.png , 3654
Captcha/res/drawable-xhdpi/smssdk_cl_divider.png , 142
Captcha/res/drawable-xhdpi/smssdk_dialog_back.9.png , 607
Captcha/res/drawable-xhdpi/smssdk_dialog_bg.9.png , 607
Captcha/res/drawable-xhdpi/smssdk_input_bg_focus.9.png , 169
Captcha/res/drawable-xhdpi/smssdk_input_bg_normal.9.png , 164
Captcha/res/drawable-xhdpi/smssdk_input_bg_special_focus.9.png , 173
Captcha/res/drawable-xhdpi/smssdk_input_bg_special_normal.9.png , 167
Captcha/res/drawable-xhdpi/smssdk_sharesdk_icon.png , 3460
Captcha/res/drawable-xxhdpi/ic_launcher.png , 1259
Captcha/res/drawable/smssdk_btn_disenable.xml , 200
Captcha/res/drawable/smssdk_btn_enable.xml , 200
Captcha/res/layout/activity_captcha.xml , 3490
Captcha/res/layout/activity_register.xml , 2841
Captcha/res/layout/smssdk_title_layout.xml , 1146
Captcha/res/values-v11/styles.xml , 334
Captcha/res/values-v14/styles.xml , 391
Captcha/res/values/strings.xml , 1462
Captcha/res/values/styles.xml , 697
Captcha/src/com/juhe/captcha/BaseActivity.java , 918
Captcha/src/com/juhe/captcha/CaptchaActivity.java , 6925
Captcha/src/com/juhe/captcha/CaptchaApplication.java , 329
Captcha/src/com/juhe/captcha/RegisterActivity.java , 5494
说明.htm , 4317
