3

I am trying to make an Android app regarding text messages. I got a source code from googling and it is works fine. However, it does not work with text messages over 80 bytes or MMS. It seems that the onReceive method cannot catch those long text messages.

Did I miss something or make any mistakes?

Here are the permissions I added..

android.permission.READ_SMS, 
android.permission.RECEIVE_SMS, 
android.permission.SEND_SMS, 
android.permission.WRITE_SMS, 
android.permission.READ_PHONE_STATE, 
android.permission.INTERNET, 
android.permission.ACCESS_NETWORK_STATE, 
android.permission.RECEIVE_MMS, 
android.permission.WRITE_EXTERNAL_STORAGE  

This is my code:

public class MySMSMonitor extends BroadcastReceiver {   
    private static String ACTIONNAME = "android.provider.Telephony.SMS_RECEIVED";  
    @Override  
    public void onReceive(Context context, Intent intent) {  
        if (intent != null && intent.getAction() != null  
            && ACTIONNAME.compareToIgnoreCase(intent.getAction()) == 0) {   
            Object[] pdu = (Object[]) intent.getExtras().get("pdus");  
            SmsMessage[] msg = new SmsMessage[pdu.length];   
            for (int i = 0; i < msg.length; i++) {  
                msg[i] = SmsMessage.createFromPdu((byte[]) pdu[i]);  
            }   
            StringBuilder sb = new StringBuilder();  
            for(SmsMessage allMsg : msg) {  
                sb.append(allMsg.getDisplayOriginatingAddress() + "&");  
                sb.append(allMsg.getDisplayMessageBody() + "&");  
                sb.append(allMsg.getTimestampMillis() + "&");  
            }  
            android.util.Log.i("SMS monitor", "data received = " + sb.toString());  
        }  
    }  
}  

Please give me some advice.

4

1 回答 1

0

我看不出你的代码有什么问题。

我实现了一个带有进度对话框的示例接收器(查看压缩项目的评论),它可以在我的手机上接收超过 80b 的消息。我建议您查看它并与您的代码进行比较。

于 2012-08-23T13:34:14.077 回答