WiFi 处于活动状态时彩信发送连接问题 (Android)

发布于 2024-10-14 02:21:37 字数 1141 浏览 10 评论 0原文

我正在开发一个 Android 应用程序,它将在内部发送彩信,而不使用本机消息应用程序。我一直在使用在 https://android.googlesource.com 找到的本机应用程序中的代码作为指导并成功创建了一个工作原型。 但是,当手机连接到 Wifi 时尝试创建 HTTP_Post 时,我遇到了一个小问题。

在下面的代码片段中,我请求 MMS 网络功能并等待 android.net.conn.CONNECTIVITY_CHANGE 意图指示连接处于活动状态。然后,我请求 TYPE_MOBILE 的 NetworkInfo 并检查它是否已连接。这就是我遇到的问题。如果 wifi 已连接,当我调用 info.isConnected() 时,它会返回 false,并且无法进行 MMS HttpPost,因为此帖子必须通过 3G/GPRS 连接进行。

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;

我可以让它工作的唯一方法是断开 wifi,此时 info.isConnected() 返回 true,我可以继续成功创建 HttpPost。但我认为这不是执行此功能的正确方法,因为本机应用程序似乎没有执行此操作。 据我所知,本机消息应用程序的 TransactionService.java 使用内部的、已弃用的类 NetworkConnectivityListener 来管理连接,但我在其代码中看不到任何修改 Wifi 连接的内容。

有没有人遇到过类似的问题或知道解决该问题的正确方法? 我注意到 ConnectivityManager 文档中有一个连接类型 TYPE_MOBILE_MMS 但我没有尝试过,因为它仅受运行 2.2 及更高版本的设备支持,我希望能够支持运行 1.6 的设备。

任何帮助将不胜感激。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

回眸一遍 2024-10-21 02:21:37

我发现该问题与在运行 2.0 及更高版本的设备上使用 android.net.ConnectivityManager.TYPE_MOBILE 连接类型有关。对于这些,您需要使用 TYPE_MOBILE_MMS,对于 1.6 设备,只需使用 TYPE_MOBILE。
无需断开 wifi。

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.

笙痞 2024-10-21 02:21:37

当 WiFi 数据连接打开时,移动数据连接将关闭。
您需要检查这两种类型。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文