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方法