广播接收器无法从移动默认消息应用程序接收消息 为什么?
在 BroadcastReceiver 中,我想从默认移动应用程序接收短信。
但是,当用户在没有互联网连接的情况下发送短信时,我会收到,但是当用户(通过 WiFi 或移动网络发送短信)时,我无法阅读消息。
public class MessageReciver extends BroadcastReceiver {
private static MessageListener mListener;
public static final String reciveSMS="android.provider.Telephony.SMS_RECEIVED";
public static final String TAG ="SmsBroadcastReceiver";
@Override
public void onReceive(Context context, Intent intent) {
Log.i("fsdfdsfdsfdgfdsg "," rerwerw");
if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")) {
Bundle data = intent.getExtras();
Object[] pdus = (Object[]) data.get("pdus");
String formate = data.getString("format");
for (int i = 0; i < pdus.length; i++) {
SmsMessage smsMessage = null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M)
{
smsMessage = SmsMessage.createFromPdu((byte[]) pdus[i], formate);
} else {
smsMessage = SmsMessage.createFromPdu((byte[]) pdus[i]);
}
String message = smsMessage.getMessageBody();
Toast.makeText(context, "Message Received: " + message, Toast.LENGTH_SHORT).show();
}
}
}
我不明白
为什么我会遇到这个问题,因为广播接收器可以从Android系统和其他Android应用程序发送或接收广播消息。它只接收(不使用互联网的短信),但每个移动消息应用程序都有默认启用选项(使用 wifi 或数据在可用时进行消息传递)。
请任何人帮助从默认移动消息应用程序接收短信
In BroadcastReceiver i want to receive sms from default Mobile application.
But when user send sms without internet connect then i receive, but when user (send sms via wifi or Mobile Network) i unable to read message.
public class MessageReciver extends BroadcastReceiver {
private static MessageListener mListener;
public static final String reciveSMS="android.provider.Telephony.SMS_RECEIVED";
public static final String TAG ="SmsBroadcastReceiver";
@Override
public void onReceive(Context context, Intent intent) {
Log.i("fsdfdsfdsfdgfdsg "," rerwerw");
if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")) {
Bundle data = intent.getExtras();
Object[] pdus = (Object[]) data.get("pdus");
String formate = data.getString("format");
for (int i = 0; i < pdus.length; i++) {
SmsMessage smsMessage = null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M)
{
smsMessage = SmsMessage.createFromPdu((byte[]) pdus[i], formate);
} else {
smsMessage = SmsMessage.createFromPdu((byte[]) pdus[i]);
}
String message = smsMessage.getMessageBody();
Toast.makeText(context, "Message Received: " + message, Toast.LENGTH_SHORT).show();
}
}
}
}
I have't understand why i face this problem , because Broadcast receiver can send or receive broadcast messages from the Android system and other Android apps. It only receive (sms without using internet), But every mobile messages application have default enable option(Use wifi or data for messaging when available).
Anyone please help receive sms from default Mobile Messages Application
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
确实如此,因为几个月前我也遇到了同样的问题。如果 wifi 关闭且 LTE 关闭,则通过广播接收器意图识别 sms_received 或 wap_push_received 来广播 MMS 和 SMS 操作。
在新的智能手机中,这些消息以绿色标记。
但如果发送方手机打开 wifi 或打开 LTE 数据模式,就会发生糟糕的情况。
这些通过 WiFi 或 LTE 发送的短信或彩信现在是聊天消息。这些聊天消息不会通过 sms_received 或 wap_push_received 广播。这些聊天消息在现代手机上以蓝色标记。如果您尝试在 Wi-Fi 关闭或 LTE 关闭的情况下向智能手机发送消息(短信或彩信),您会收到通知,现在您的消息将仅作为普通短信或彩信发送。
您可以通过 contentresolver content://im/chat 找到这些聊天消息
不幸的是,我还不知道如何接收广播的聊天消息。现在,我每 1 秒拉一次内容解析器以获取新的聊天消息。
It's true, since some month before I have the same problem. If wifi is off and LTE is off, then MMS and SMS actions are broadcasted with sms_received or wap_push_received are recognized by broadcast receiver intent.
In new Smartphones these messages are marked by green color.
But if the sender phone turn on wifi or turn on LTE data mode, then shit happens.
These sms or mms over wifi or over LTE are now CHAT messages. These chat messages are not broadcasted by sms_received or wap_push_received. These CHAT messages are blue marked on modern phones. If you try to send messages (sms or mms) to an smartphone with wifi off or LTE off, you will be informed that now your messages will be send only as normal SMS or MMS.
You can find these CHAT messages over contentresolver content://im/chat
Unfortunately I doesn't know yet, how to receive broadcasted chat messages. For now I pull every 1 second the contentresolver for new chat messages.
已经注册您的接收器了吗?
试试这个
AndroidManifest.xml
MainActivity.java
already register your receiver yet?
try this
AndroidManifest.xml
MainActivity.java