我試圖通過發送文本到用戶的手機然後得到它並匹配用戶給的號碼和文本剛剛來自的數字來確認用戶的電話號碼..問題在於儘管文本匹配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();
}
}
}
}
你在比較字符串嗎?也許是編碼的東西? –
請提供您的代碼在哪裏比較值 –
是啊...我比較兩個字符串...詳細說明它如何可以編碼? –