Question

I want to send a MMS using the stock MMS source. Before more explanation, I want to say that it does work on some android versions but 4.0.3 and 4.0.4.

In my service, I ask the device to enable the MMS network feature using the following code:

createWakeLock();

int result = mConnMgr.startUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE, PhoneEx.FEATURE_ENABLE_MMS);

Log.v(TAG, "beginMmsConnectivity: result=" + result);

switch (result) {
    case PhoneEx.APN_ALREADY_ACTIVE:
    case PhoneEx.APN_REQUEST_STARTED:
        acquireWakeLock();
        return result;
}

throw new IOException("Cannot establish MMS connectivity");

On some devices (Xperia T running 4.0.3), it throws an exception because result equals PhoneEx.APN_TYPE_NOT_AVAILABLE. The MMS is enabled in my phone settings and I can send one with the stock mms app.

On other devices (HTC Desire S running 4.0.4), the problem is located a bit further, in the ConnectivityBroadcastReceiver. Here is my code:

private class ConnectivityBroadcastReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(final Context context, Intent intent) {
        String action = intent.getAction();

        mNetworkInfo = (NetworkInfo) intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
        mOtherNetworkInfo = (NetworkInfo) intent.getParcelableExtra(ConnectivityManager.EXTRA_OTHER_NETWORK_INFO);

        networkAttempt++;

        if (networkAttempt < APN_RETRY_ATTEMPTS) {
            // Check availability of the mobile network.
            if ((mNetworkInfo == null) || (mNetworkInfo.getType() != ConnectivityManager.TYPE_MOBILE_MMS)) {
                // ERROR is located here, it returns TYPE_MOBILE :s
                Log.v(TAG, "   type is not TYPE_MOBILE_MMS, bail");
                return;
            }
        }
        ...

As you can see in the comment, mNetworkInfo.getType() returns TYPE_MOBILE but I expect TYPE_MOBILE_MMS.

So, my question is the following: Did I make something wrong ? Or, Is there another way to do that ?

Ps: It works on devices running Android 2.3 to 3.2 and 4.1 and above.

Was it helpful?

Solution

It appears on some devices, with some providers, the TYPE_MOBILE isn't the default MMS gateway, you have to use another one. Here is the solution I found that solved my problem.

I hope this could help someone else.

// Take a wake lock so we don't fall asleep before the message is downloaded.
createWakeLock();

// Let's try every type
int result = -1;
int[] apnTypes = new int[] {ConnectivityManager.TYPE_MOBILE, ConnectivityManager.TYPE_MOBILE_MMS, ConnectivityManager.TYPE_MOBILE_DUN, ConnectivityManager.TYPE_MOBILE_HIPRI, ConnectivityManager.TYPE_MOBILE_SUPL};
for (int i=0; i<apnTypes.length; i++)
{
    result = mConnMgr.startUsingNetworkFeature(apnTypes[i], PhoneEx.FEATURE_ENABLE_MMS);
    Log.v(TAG, "beginMmsConnectivity: result=" + result);
    switch (result)
    {
        case PhoneEx.APN_ALREADY_ACTIVE:
        case PhoneEx.APN_REQUEST_STARTED:
            acquireWakeLock();
            return result;
    }
}

// None found
throw new IOException("Cannot establish MMS connectivity");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top