receive MMS programmatically

2,192 views
Skip to first unread message

Tez

unread,
Feb 1, 2011, 8:34:18 AM2/1/11
to android-platform
I have been searching for examples on how to receive an MMS
programmatically, but could find none.
How does the system do it internally?

Cheers,
Earlence

Mike Playle

unread,
Feb 1, 2011, 9:28:05 AM2/1/11
to android-...@googlegroups.com
On Tue, 2011-02-01 at 05:34 -0800, Tez wrote:
> I have been searching for examples on how to receive an MMS
> programmatically, but could find none.
> How does the system do it internally?

Here's how we receive data SMSes in our application. I wouldn't have
thought that receiving an MMS would be very different.

In AndroidManifest.xml:

<receiver android:name=".receiver.SMSReceiver">
<intent-filter>
<action android:name="android.intent.action.DATA_SMS_RECEIVED" />
<data android:scheme="sms"/>
<data android:host="localhost"/>
<data android:port="16387"/>
</intent-filter>
</receiver>

In SMSReceiver.java:

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

public class SMSReceiver extends BroadcastReceiver {
private static final String LOG_TAG = "SMSReceiver";

static final String ACTION =
"android.intent.action.DATA_SMS_RECEIVED";

private SmsMessage[] getMessagesFromIntent(Intent intent)
{
SmsMessage retMsgs[] = null;
Bundle bdl = intent.getExtras();
try{
Object pdus[] = (Object [])bdl.get("pdus");
retMsgs = new SmsMessage[pdus.length];
for(int n=0; n < pdus.length; n++)
{
byte[] byteData = (byte[])pdus[n];
retMsgs[n] =
SmsMessage.createFromPdu(byteData);
}
}
catch(Exception e)
{
Log.e("GetMessages", "fail", e);
}
return retMsgs;
}

@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(ACTION)) {
StringBuilder buf = new StringBuilder();
Bundle bundle = intent.getExtras();
if (bundle != null) {
SmsMessage[] messages = getMessagesFromIntent(intent);
for (int i = 0; i < messages.length; i++) {
SmsMessage message = messages[i];
buf.append("Received SMS from ");
buf.append(message.getDisplayOriginatingAddress());
buf.append(" - ");
buf.append(message.getDisplayMessageBody());
}
}
Log.i(LOG_TAG, "onReceiveIntent: " + buf);

} else {
Log.i(LOG_TAG, "Bad intent: " + intent.getAction());
}
}
}

Hope this helps!

Mike Playle
RealVNC


Adrienne Porter Felt

unread,
Feb 1, 2011, 10:30:09 AM2/1/11
to android-...@googlegroups.com
For MMS, you want to have:

<intent-filter>

<action android:name="android.provider.Telephony.WAP_PUSH_RECEIVED" />

<data android:mimeType="application/vnd.wap.mms-message" />

</intent-filter>


and also the RECEIVE_MMS permission.


A quick google search for the data type gives this example:

http://code.google.com/p/android-notifier/source/browse/trunk/AndroidNotifier/src/org/damazio/notifier/service/MmsReceiver.java?r=141




--
You received this message because you are subscribed to the Google Groups "android-platform" group.
To post to this group, send email to android-...@googlegroups.com.
To unsubscribe from this group, send email to android-platfo...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-platform?hl=en.




--
APF

Tez

unread,
Feb 1, 2011, 12:44:04 PM2/1/11
to android-platform
thanks. that was the information I needed.

On Feb 1, 4:30 pm, Adrienne Porter Felt <a...@berkeley.edu> wrote:
> For MMS, you want to have:
>
> <intent-filter>
>
> <action android:name="android.provider.Telephony.WAP_PUSH_RECEIVED" />
>
> <data android:mimeType="application/vnd.wap.mms-message" />
>
> </intent-filter>
>
> and also the RECEIVE_MMS permission.
>
> A quick google search for the data type gives this example:
>
> http://code.google.com/p/android-notifier/source/browse/trunk/Android...
> > android-platfo...@googlegroups.com<android-platform%2Bunsu...@googlegroups.com>
> > .

Bobby Nie

unread,
Mar 8, 2017, 10:33:14 AM3/8/17
to android-platform

A quick google search for the data type gives this example:

http://code.google.com/p/android-notifier/source/browse/trunk/AndroidNotifier/src/org/damazio/notifier/service/MmsReceiver.java?r=141


do anyone has thiscode I need to deal MMS too

在 2011年2月1日星期二 UTC+8下午9:34:18,Tez写道:
Reply all
Reply to author
Forward
0 new messages