Android的多媒体广播接收器 [英] Android MMS Broadcast receiver
问题描述
我工作的一个MMS广播接收机。它已接收彩信的时候开始,但是我不知道如何捕捉/解析彩信的内容就像是用手机短信在这个例子中完成的:
I am working on a MMS broadcast receiver. It already starts when receiving a MMS but I dont know how to capture / parse the contents of the mms like it is done with sms in this example:
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());
}
}
}
}
}
感谢
推荐答案
读了几个相关的问题之后:
After reading a couple of related questions:
检测新的MMS(Android 2.1的)
检测彩信在Android上。
看来这feautre大多是支持的,但没有正式,所以你不会找到太多的文档。因此,<一个href="http://www.anddev.org/other-coding-problems-f5/where-can-i-find-information-about-sending-receiving-mms-t51284.html"相对=nofollow>链接之一内的那些相关的问题点所提供的东西,看起来像一些你可能会感兴趣。
It seems this feautre is mostly supported, but not officially, so you wouldn't find much on the documentation. So, one of the links provided within those related questions points to something which looks like something you may be interested in.
特别有趣的这块code:
Specially interesting this piece of code:
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());
}
}
如果你看看,测试并给我们一些反馈?
What if you have a look, test and give us some feedback?
问候。
这篇关于Android的多媒体广播接收器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!