android:
id="@+id/now"
android:
layout_width="fill_parent"
android:
layout_height="wrap_content"
android:
layout_above="@+id/savecord"
android:
layout_toRightOf="@+id/cord"
android:
gravity="center_horizontal"
android:
visibility="gone"
android:
text="提示信息"
android:
textColor="#aaaaaa"/>
一个主Activity代码如下:
[html]viewplaincopy在CODE上查看代码片派生到我的代码片
publicclassMainActivityextendsActivityimplementsOnClickListener{
privateEditTextphone;
privateEditTextcord;
privateTextViewnow;
privateButtongetCord;
privateButtonsaveCord;
privateStringiPhone;
privateStringiCord;
privateinttime=60;
privatebooleanflag=true;
@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
init();
SMSSDK.initSDK(this,"<您的appkey>","<您的appsecret>");
EventHandlereh=newEventHandler(){
@Override
publicvoidafterEvent(intevent,intresult,Objectdata){
Messagemsg=newMessage();
msg.arg1=event;
msg.arg2=result;
msg.obj=data;
handler.sendMessage(msg);
}
};
SMSSDK.registerEventHandler(eh);
}
privatevoidinit(){
phone=(EditText)findViewById(R.id.phone);
cord=(EditText)findViewById(R.id.cord);
now=(TextView)findViewById(R.id.now);
getCord=(Button)findViewById(R.id.getcord);
saveCord=(Button)findViewById(R.id.savecord);
getCord.setOnClickListener(this);
saveCord.setOnClickListener(this);
}
@Override
publicvoidonClick(Viewv){
switch(v.getId()){
caseR.id.getcord:
if(!
TextUtils.isEmpty(phone.getText().toString().trim())){
if(phone.getText().toString().trim().length()==11){
iPhone=phone.getText().toString().trim();
SMSSDK.getVerificationCode("86",iPhone);
cord.requestFocus();
getCord.setVisibility(View.GONE);
}else{
Toast.makeText(MainActivity.this,"请输入完整电话号码",Toast.LENGTH_LONG)how();
phone.requestFocus();
}
}else{
Toast.makeText(MainActivity.this,"请输入您的电话号码",Toast.LENGTH_LONG).show();
phone.requestFocus();
}
break;
caseR.id.savecord:
if(!
TextUtils.isEmpty(cord.getText().toString().trim())){
if(cord.getText().toString().trim().length()==4){
iCord=cord.getText().toString().trim();
SMSSDK.submitVerificationCode("86",iPhone,iCord);
flag=false;
}else{
Toast.makeText(MainActivity.this,"请输入完整验证码",Toast.LENGTH_LONG).show();
cord.requestFocus();
}
}else{
Toast.makeText(MainActivity.this,"请输入验证码",Toast.LENGTH_LONG).show();
cord.requestFocus();
}
break;
default:
break;
}
}
//验证码送成功后提示文字
privatevoidreminderText(){
now.setVisibility(View.VISIBLE);
handlerText.sendEmptyMessageDelayed(1,1000);
}
HandlerhandlerText=newHandler(){
publicvoidhandleMessage(Messagemsg){
if(msg.what==1){
if(time>0){
now.setText("验证码已发送"+time+"秒");
time--;
handlerText.sendEmptyMessageDelayed(1,1000);
}else{
now.setText("提示信息");
time=60;
now.setVisibility(View.GONE);
getCord.setVisibility(View.VISIBLE);
}
}else{
cord.setText("");
now.setText("提示信息");
time=60;
now.setVisibility(View.GONE);
getCord.setVisibility(View.VISIBLE);
}
};
};
Handlerhandler=newHandler(){
@Override
publicvoidhandleMessage(Messagemsg){
//TODOAo-generatedmethodstub
super.handleMessage(msg);
intevent=msg.arg1;
intresult=msg.arg2;
Objectdata=msg.obj;
Log.e("event","event="+event);
if(result==SMSSDK.RESULT_COMPLETE){
//短信注册成功后,返回MainActivity,然后提示新好友
if(event==SMSSDK.EVENT_SUBMIT_VERIFICATION_CODE){//提交验证码成功,验证通过
Toast.makeText(getApplicationContext(),"验证码校验成功",Toast.LENGTH_SHORT).show();
handlerText.sendEmptyMessage
(2);
}elseif(event==SMSSDK.EVENT_GET_VERIFICATION_CODE){//服务器验证码发送成功
reminderText();
Toast.makeText(getApplicationContext(),"验证码已经发送",Toast.LENGTH_SHORT).show();
}elseif(event==SMSSDK.EVENT_GET_SUPPORTED_COUNTRIES){//返回支持发送验证码的国家列表
Toast.makeText(getApplicationContext(),"获取国家列表成功",Toast.LENGTH_SHORT).show();
}
}else{
if(flag){
getCord.setVisibility(View.VISIBLE);
Toast.makeText(MainActivity.this,"验证码获取失败,请重新获取",T