I have a class that extends BroadcastReceiver
and reads code from an SMS and pastes it automatically in an EditText
, this works perfectly on Samsung and Nexus Emulator, but now it's not working on Huawei , it does copy the text.. but then user needs to paste it manually..
This is my code:
public class SimpleSmsReciever extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Bundle pudsBundle = intent.getExtras();
Object[] pdus = (Object[]) Objects.requireNonNull(pudsBundle).get("pdus");
String format = pudsBundle.getString("format");
SmsMessage messages =SmsMessage.createFromPdu((byte[]) Objects.requireNonNull(pdus)[0],format);
// check if sender is specificSender
if(messages.getOriginatingAddress().equalsIgnoreCase("specificSender")) {
// get only the numbers from the sms
String number = messages.getMessageBody().replaceAll("[^0-9]", "");
// place the code in the edit text
if(VerifyActivity.isVerifyRunning) {
VerifyActivity.et_code.setText(number);
} else if(BaseActivity.isChangeNumberOn)
{
EditText et = BaseActivity.changeNumber.findViewById(R.id.et_code);
et.setText(number);
}
}
}
}
Do you have any idea what might cause this?
is it related to Huawei devices or is there something I should add to my code?
Thank You.