在登录android应用程序之前,我想输入我的号码并按下按钮。这个按钮处理发送短信到号码进入,所以如果收到的消息给我,它将进入应用程序,否则它将显示一条消息,以验证/验证号码。
发布于 2011-12-13 19:40:00
我找到了解决方案。使用BroadcastReceiver的onReceive方法
`
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();
}
}`
https://stackoverflow.com/questions/7646122
复制相似问题