安卓批量发送短信代码在OPPO/红米/VIVO设备失效求助
Hey there, let's break down this batch SMS issue you're hitting. It's really common for OEMs like OPPO, Xiaomi (Redmi), and VIVO to have stricter SMS sending rules or modified Telephony frameworks compared to Samsung — that's exactly why your code works smoothly on Samsung but chokes on other devices, only sending to the first number.
Looking at your startSendMessages() snippet, you kick off with the first number and increment a counter, but the root problem is almost certainly how you're handling broadcast receivers for SMS sent statuses. Most non-Samsung devices force you to wait for confirmation that the previous SMS was sent before triggering the next one. If you're firing off requests back-to-back without listening for that confirmation, these OEMs will block subsequent messages to prevent spam.
Here's how to fix this step by step:
Fix the Broadcast Receiver Flow
Make sure yourregisterBroadCastReceivers()properly registers a receiver forSmsManager.SENT_SMS_ACTION, and only triggersendNextMessage()once you confirm the last SMS was sent successfully. Here's a revised implementation:// 监听短信发送状态的广播接收器 private BroadcastReceiver sentSMSReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { switch (getResultCode()) { case Activity.RESULT_OK: // 短信发送成功,推进计数器并发送下一条 mMessageSentCount++; if (mMessageSentCount < MobNumber.size()) { sendSMS(MobNumber.get(mMessageSentCount).toString(), str_Address); } else { // 所有短信发送完成,记得注销接收器 unregisterReceiver(this); // 如果注册了送达接收器,也一起注销 if (deliveredSMSReceiver != null) { unregisterReceiver(deliveredSMSReceiver); } } break; // 处理各种发送失败的情况,可选择重试或直接跳过 case SmsManager.RESULT_ERROR_GENERIC_FAILURE: case SmsManager.RESULT_ERROR_NO_SERVICE: case SmsManager.RESULT_ERROR_NULL_PDU: case SmsManager.RESULT_ERROR_RADIO_OFF: mMessageSentCount++; if (mMessageSentCount < MobNumber.size()) { sendSMS(MobNumber.get(mMessageSentCount).toString(), str_Address); } break; } } }; // 完善接收器注册方法 private void registerBroadCastReceivers() { IntentFilter sentFilter = new IntentFilter(SmsManager.SENT_SMS_ACTION); registerReceiver(sentSMSReceiver, sentFilter); // 可选:注册短信送达状态接收器(如果需要确认用户收到) IntentFilter deliveredFilter = new IntentFilter(SmsManager.DELIVERED_SMS_ACTION); deliveredSMSReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { // 处理送达逻辑 } }; registerReceiver(deliveredSMSReceiver, deliveredFilter); }Never Send SMS in Parallel
Don't try to fire off multiple SMS requests at once. These OEMs have strict rate limits to combat spam, so you must send messages sequentially. Wait for the sent confirmation broadcast before triggering the next message — this is the biggest mistake that causes partial sends on non-Samsung devices.Verify OEM-Specific Permissions & Restrictions
Devices like OPPO and VIVO have their own permission systems beyond Android's default. Double-check:- Your app has the
SEND_SMSpermission granted (go to app settings to confirm) - No "Auto-start" or "Background activity" restrictions are enabled for your app — these can block broadcast receivers from firing
- Some devices require you to enable "SMS access" specifically for your app in their security settings
- Your app has the
Correctly Use SmsManager's sendTextMessage
Ensure yoursendSMSmethod includes the pending intent for sending status — this is how the broadcast receiver gets notified. For Android 12+, use the correct pending intent flags:private void sendSMS(String phoneNumber, String message) { SmsManager smsManager = SmsManager.getDefault(); // 针对Android 12+使用FLAG_IMMUTABLE PendingIntent sentPI = PendingIntent.getBroadcast( this, 0, new Intent(SmsManager.SENT_SMS_ACTION), PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE ); smsManager.sendTextMessage(phoneNumber, null, message, sentPI, null); }
The main takeaway here is that Samsung is more lenient with parallel SMS sends, but other OEMs enforce sequential sending with proper broadcast confirmation. By adjusting your code to wait for each SMS to be marked as sent before moving to the next, you'll fix the issue on OPPO, Redmi, and VIVO devices.
内容的提问来源于stack exchange,提问作者Ramesh Yogu




