0
在登录到android应用程序之前,我想输入我的号码并按下按钮。 这个按钮处理发送短信给号码进入,所以如果收到的消息它会进入应用程序,否则它会显示一条消息来验证/验证号码。如何使用SMS验证验证“日志记录”到Android应用程序
在登录到android应用程序之前,我想输入我的号码并按下按钮。 这个按钮处理发送短信给号码进入,所以如果收到的消息它会进入应用程序,否则它会显示一条消息来验证/验证号码。如何使用SMS验证验证“日志记录”到Android应用程序
我找到了解决方案。 使用的广播接收器
`
public void onReceive(Context context, Intent intent)
{
//---get the SMS message passed in---
Bundle bundle = intent.getExtras();
if (bundle != null)
{
//---retrieve the SMS message received---
Object[] pdus = (Object[]) bundle.get("pdus");
msgs = SmsMessage.createFromPdu((byte[])pdus[0]);
Log.i(TAG, msgs.getMessageBody());
Intent intent2 = new Intent("com.uba.messagereceived");
str = "SMS From "+msgs.getOriginatingAddress()+":"+msgs.getMessageBody().toString()+"...";
intent2.putExtra("letter", str);
intent2.putExtra("address", msgs.getOriginatingAddress());
intent2.putExtra("txt", msgs.getMessageBody().toString());
context.sendBroadcast(intent2);
}
//---display the new SMS message---
Toast.makeText(context, str, Toast.LENGTH_SHORT).show();
if(yMsg == msgg && xNum == no)
{
setStatus("valid");
Intent mp = new Intent(context,UserMainPage.class);
context.startActivity(mp);
Toast.makeText(context,"The Validation completed: "+this.getStatus(), Toast.LENGTH_SHORT).show();
}
else
{
setStatus("not Valid");
Toast.makeText(context,"The Validation completed: "+this.getStatus(), Toast.LENGTH_SHORT).show();
}
}
`
所述的onReceive方法