Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Really Prefer Network: select my own network provider as soon as it is available (from code)

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.

like image 711
wligtenberg Avatar asked Oct 03 '10 14:10

wligtenberg


1 Answers

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.

like image 101
Dave MacLean Avatar answered Nov 09 '22 21:11

Dave MacLean