真正喜欢网络:一旦可用就选择我自己的网络提供商(来自代码)
我住在边境附近,在另一个国家工作。所以我选择了我自己的网络提供商作为最喜欢的。然而,我注意到它会尽可能长时间地与提供商保持联系。因此,当我从我的国家出发时,即使我跨越边境,我也会保留我的网络,但是,当我反过来时,即使我最喜欢的网络已经可用,它也会保留外国网络。我知道这一点,因为当我想手动选择它时,它可以从列表中找到。
现在,我想创建一个应用程序,在漫游时每次连接到另一个手机信号塔时都会自动搜索我的首选网络。 现在我明白了,以前我可以用广播接收器收听小区位置变化,但现在这是不可能的。 (这是一个遗憾) 我从中读到: 以编程方式连接到其他网络运营商 出于安全原因,我似乎无法从应用程序中选择另一个提供商。 (至少有记录的 api 调用)。
但是,我不关心是否有公共 api,因为我不打算在 Android Market 中分发它。它只是一个让我的生活更轻松的应用程序,可能会开放源代码,以便其他人可以使用它(如果他们愿意)。
我可以使用一些提示来使其正常工作。 因此,也许还有其他我可以收听的广播内容,例如信号强度或其他内容,这将启动我的代码来检查我是否可以切换网络。 我希望它作为广播接收器工作,我还读到,当使用服务中的小区位置时,当屏幕关闭时我不会获得更新,在这种情况下,这违背了目的。
然后,我将非常感谢一些关于如何在 Android 源代码中搜索可用于自动选择网络的内容的提示/指针。
I live near the border and work in another country. So I have selected my own network provider as the favorite. However, I notice that it sticks with the provider for as long as it can. So when I start from my country I keep my network even when I am across the border, however, when I go the other way around, it will keep the foreign network even when my favorite network is already available. I know this, because when I want to manually select it, it is available from the list.
Now, I would like to create an application that would automatically search for my preferred network when it is roaming, each time it connects to another cell tower.
Now I understand, that previously I could have listened to Cell Location changed with a broadcast receiver, but that is now impossible. (Which is a pity)
And I read from this:
Programatically connecting to another Network operators
That it seems that I would be unable to select another provider from an application for security reasons. (At least with documented api calls).
However, I don't care about public api or not, because I don't intent to distribute this in the Android Market. It is just an app to make MY life easier, will probably open up the source code, so other people can use it if they want to.
I could use some hints, to get this working though.
So maybe there are other things that are broadcast for which I can listen to, like signal strength or something, this would start my code to check if I can switch network.
I would prefer this to work as a Broadcast Receiver, I also have read that when using Cell location from a Service that I won't get updates when the screen is turned off, which in this case defeats the purpose.
And then, I would greatly appreciate some hints/pointers as for how to search the Android source for stuff that I can use to select the network automatically.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于听起来您可能正在网络之间的可预测路径上行驶,因此您是否考虑过使用 LocationManager 的 ProximityAlert 功能?您围绕某个位置定义一个圆圈,当您的设备进入/退出该圆圈时,就会向您的接收器发出广播。
我在 Pro Android 3 第 17 章中写了一个关于此的部分。我们的网站上有一个示例应用程序:
http:// www.androidbook.com/projects
单击项目 zip 文件的链接,然后查找 ProAndroid3_Ch17_Maps.zip
上面的链接有下载和导入的说明。 zip 内的项目名为 ProximityAlertDemo。这是非常基本的,只是为了显示接近警报本身,但将其合并到应用程序或服务中应该不会太难。恐怕我无法为您提供有关如何从代码切换网络的答案。启动“设置”屏幕的建议似乎是您目前最好的选择。
Since it sounds like you might be traveling on a predictable path between the networks, have you considered using the ProximityAlert capability of the LocationManager? You define a circle around some location, and when your device enters/exits that circle, a broadcast is issued to your receiver.
I wrote a section on this in Pro Android 3, chapter 17. There's a sample application on our web site:
http://www.androidbook.com/projects
Click on the link for the project zip files, then look for ProAndroid3_Ch17_Maps.zip
There are instructions for downloading and importing from the link above. The project inside the zip is called ProximityAlertDemo. It's very basic, just to show the Proximity Alert itself, but it shouldn't be too hard to incorporate it into an app or a service. I'm afraid I don't have an answer for you on how to switch the networks from code though. The suggestion to launch into the Settings screen seems to be your best bet at the moment.