MMS sending connectivity issues when wifi is active (Android)

淺唱寂寞╮ 提交于 2019-12-24 18:52:34

问题


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.



来源:https://stackoverflow.com/questions/4796541/mms-sending-connectivity-issues-when-wifi-is-active-android

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!