我试图通过发送文本到用户的手机然后得到它并匹配用户给的号码和文本刚刚来自的数字来确认用户的电话号码..问题在于尽管文本匹配100%,但我已经以很多方式确认了字节数组不匹配,因此“电话号码”不匹配,并且确认是不可能的。这是一件真实的事情:通过网络更改字节数组发送值?字符串通过文本更改字节数组值发送
文本发送:
String user_phone_number = phoneNumber.getText().toString();
String number = "" + user_phone_number;
String verificationCode = "717345221";
String message = verificationCode + user_phone_number;
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(number, null, message, null, null);
文本收到:
if (intent.getAction()
.equals("android.provider.Telephony.SMS_RECEIVED")) {
Bundle bundle = intent.getExtras();
SmsMessage[] msgs = null;
String msgFrom;
if (bundle != null) {
try {
Object[] pdus = (Object[]) bundle.get("pdus");
msgs = new SmsMessage[pdus.length];
for (int i = 0; i < msgs.length; i++) {
msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
msgFrom = msgs[i].getOriginatingAddress();
String msgBody = msgs[i].getMessageBody();
String verificationCode = "717345221";
if (msgBody.startsWith(verificationCode)) {
msgBody = msgBody.substring(verificationCode
.length());
if (msgBody.trim() == msgFrom.trim()) {
showCorrectNotification(context);
try {
Intent o = new Intent(context,
ProfileInformation.class);
o.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(o);
} catch (Exception e) {
e.toString();
}
}
}
}
你在比较字符串吗?也许是编码的东西? –
请提供您的代码在哪里比较值 –
是啊...我比较两个字符串...详细说明它如何可以编码? –