MMS sending connectivity issues when wifi is activ

2019-08-27 02:41发布

问题:

I'm working on an Android application that will send MMS internally without using the native messaging app. I've been using the code from the native app that I found at https://android.googlesource.com as a guide and have managed to create a working prototype. However, I'm having a slight issue when trying to make the HTTP_Post when the phone is connected to Wifi.

In the code snippet below I request the MMS network feature and wait for the android.net.conn.CONNECTIVITY_CHANGE intent indicating the connection is active. I then request the NetworkInfo for TYPE_MOBILE and check that it is connected. This is where I hit the issue. If the wifi is connected, when I call info.isConnected() it returns false and the MMS HttpPost cannot be made as this post must be made through the 3G/GPRS connection.

ConnectivityManager.startUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE, "enableMMS");
//wait for android.net.conn.CONNECTIVITY_CHANGE intent
NetworkInfo info = connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
if (!info.isConnected())
     return;

The only way I can get it to work is by disconnecting the wifi at which point info.isConnected() returns true and I can go on to make the HttpPost successfully. But I don't think this is the correct way of performing this function as the native app doesn't seem to do this. From what I can see, the native messaging app's TransactionService.java uses an internal, deprecated class, NetworkConnectivityListener, to manage the connection but I can't see anything in its code that modifies the Wifi connection.

Has anyone had a similar issue to this or know of the correct way to work around it? I noticed in the ConnectivityManager documentation there's a connection type TYPE_MOBILE_MMS but I haven't tried this as it's only supported by devices running 2.2 and above and I want to be able to support devices running 1.6.

Any help would be most appreciated.

回答1:

I found out the issue had to do with using the android.net.ConnectivityManager.TYPE_MOBILE connection type on devices running 2.0 and above. With these you need to use TYPE_MOBILE_MMS and for 1.6 devices just use TYPE_MOBILE. There is no need to disconnect the wifi.



回答2:

When WiFi data connections turns on, mobile data connection switches off. You need to check for both types.



标签: android wifi mms