Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send image via MMS in Android?

I am working on a multimedia application. I am capturing one image through the camera and want to send that image with a text to some other number. But I am not getting how to send the image via the MMS.

like image 451
Sanjay Avatar asked Jun 04 '10 09:06

Sanjay


People also ask

Why can't I send MMS pictures on my Android?

If the smartphone refuses to send a picture message, check from the drop-down menu if the mobile data is switched on. If you are using Wi-Fi try temporarily disabling it and use cellular data. Service providers don't allow you to send MMS over Wi-Fi so make sure you have an active data package or sufficient balance.


1 Answers

MMS is just a htttp-post request. You should perform the request using extra network feature :

final ConnectivityManager connMgr = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE); final int result = connMgr.startUsingNetworkFeature( ConnectivityManager.TYPE_MOBILE, Phone.FEATURE_ENABLE_MMS); 

If you get result with Phone.APN_REQUEST_STARTED value, you have to wait for proper state. Register BroadCastReciver and wait until Phone.APN_ALREADY_ACTIVE appears:

final IntentFilter filter = new IntentFilter(); filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); context.registerReceiver(reciver, filter); 

If connection background is ready, build content and perform request. If you want to do that using android's internal code, please use this:

final SendReq sendRequest = new SendReq();     final EncodedStringValue[] sub = EncodedStringValue.extract(subject);     if (sub != null && sub.length > 0) {         sendRequest.setSubject(sub[0]);     }     final EncodedStringValue[] phoneNumbers = EncodedStringValue             .extract(recipient);     if (phoneNumbers != null && phoneNumbers.length > 0) {         sendRequest.addTo(phoneNumbers[0]);     }      final PduBody pduBody = new PduBody();      if (parts != null) {         for (MMSPart part : parts) {             final PduPart partPdu = new PduPart();             partPdu.setName(part.Name.getBytes());             partPdu.setContentType(part.MimeType.getBytes());             partPdu.setData(part.Data);             pduBody.addPart(partPdu);         }     }      sendRequest.setBody(pduBody);      final PduComposer composer = new PduComposer(this.context, sendRequest);     final byte[] bytesToSend = composer.make();      HttpUtils.httpConnection(context, 4444L, MMSCenterUrl,             bytesToSendFromPDU, HttpUtils.HTTP_POST_METHOD, !TextUtils                     .isEmpty(MMSProxy), MMSProxy, port); 

MMSCenterUrl: url from MMS-APNs, MMSProxy: proxy from MMS-APNs, port: port from MMS-APNs

Note that some classes are from internal packages. Download from android git is required.

The request should be done with url from user's apn-space...code..:

public class APNHelper {  public class APN {     public String MMSCenterUrl = "";     public String MMSPort = "";     public String MMSProxy = "";  }  public APNHelper(final Context context) {     this.context = context; }     public List<APN> getMMSApns() {          final Cursor apnCursor = this.context.getContentResolver().query(Uri.withAppendedPath(Telephony.Carriers.CONTENT_URI, "current"), null, null, null, null); if ( apnCursor == null ) {         return Collections.EMPTY_LIST;     } else {         final List<APN> results = new ArrayList<APN>();              if ( apnCursor.moveToFirst() ) {         do {             final String type = apnCursor.getString(apnCursor.getColumnIndex(Telephony.Carriers.TYPE));             if ( !TextUtils.isEmpty(type) && ( type.equalsIgnoreCase(Phone.APN_TYPE_ALL) || type.equalsIgnoreCase(Phone.APN_TYPE_MMS) ) ) {                 final String mmsc = apnCursor.getString(apnCursor.getColumnIndex(Telephony.Carriers.MMSC));                 final String mmsProxy = apnCursor.getString(apnCursor.getColumnIndex(Telephony.Carriers.MMSPROXY));                 final String port = apnCursor.getString(apnCursor.getColumnIndex(Telephony.Carriers.MMSPORT));                                   final APN apn = new APN();                 apn.MMSCenterUrl = mmsc;                 apn.MMSProxy = mmsProxy;                 apn.MMSPort = port;                 results.add(apn);             }         } while ( apnCursor.moveToNext() );               }                       apnCursor.close();         return results;     } }  private Context context;  } 
like image 185
Damian Kołakowski Avatar answered Sep 19 '22 06:09

Damian Kołakowski