2011-05-27 252 views
2

我正在使用MMS廣播接收器。它接收彩信的時候就已經開始,但我不知道如何捕捉/解析彩信的內容就像是用手機短信在這個例子中完成的:Android MMS廣播接收器

import android.content.BroadcastReceiver; 
import android.content.Context; 
import android.content.Intent; 
import android.os.Bundle; 
import android.telephony.SmsMessage; 
import android.util.Log; 

public class SMSBroadcastReceiver extends BroadcastReceiver { 

     private static final String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED"; 
     private static final String TAG = "SMSBroadcastReceiver"; 

     @Override 
     public void onReceive(Context context, Intent intent) { 
      Log.i(TAG, "Intent recieved: " + intent.getAction()); 

       if (intent.getAction() == SMS_RECEIVED) { 
        Bundle bundle = intent.getExtras(); 
        if (bundle != null) { 
         Object[] pdus = (Object[])bundle.get("pdus"); 
         final SmsMessage[] messages = new SmsMessage[pdus.length]; 
         for (int i = 0; i < pdus.length; i++) { 
          messages[i] = SmsMessage.createFromPdu((byte[])pdus[i]); 
         } 
         if (messages.length > -1) { 
          Log.i(TAG, "Message recieved: " + messages[0].getMessageBody()); 
         } 
        } 
       } 
      } 
    } 

感謝

+0

我在做類似的事情! http://stackoverflow.com/questions/14452808/sending-and-receiving-mms-in-android – toobsco42 2013-01-22 07:23:19

回答

2

讀了幾個相關的問題後, :

Detecting new MMS (Android 2.1)
Detecting MMS messages on Android

看來這feautre大多是支持的,但沒有正式,所以你不會發現太多的文檔umentation。因此,這些相關的問題中提供one of the links指向一些東西,看起來像是你可能有興趣在

特別有趣的這段代碼:

public void startMMSMonitoring() { 
     try { 
     monitorStatus = false; 
     if (!monitorStatus) { 
      contentResolver.registerContentObserver(Uri.parse("content://mms-sms"), true, mmsObserver); 

      Uri uriMMSURI = Uri.parse("content://mms"); 
      Cursor mmsCur = mainActivity.getContentResolver().query(uriMMSURI, null, "msg_box = 4", null, "_id"); 
      if (mmsCur != null && mmsCur.getCount() > 0) { 
       mmsCount = mmsCur.getCount(); 
       Log("", "MMSMonitor :: Init MMSCount ==" + mmsCount); 
      } 
     } 
     } catch (Exception e) { 
     Log("", "MMSMonitor :: startMMSMonitoring Exception== "+ e.getMessage()); 
     } 
    } 

如果你看看,測試並給我們一些反饋?

關於。