WifiManager.getScanResults() - clarifications (automatic scans, sleep etc) - android

I would like some clarifications on the behavior of WifiManager.getScanResults(), namely :
When wireless is enabled
Does android scan for access points on a fixed interval ? Can one query/change the interval ? Can one query the time of the last scan ? For a discussion see this answer
What happens when the wireless radio is turned off (sleeps) - while wifi is still enabled - will getScanResults() go on returning the last scan results ? How would one know if it's time for startScan()?
When wireless is disabled
getScanResults() would return the last scan results ? Or an empty List ? Or null (it does return null at times and this is not handled by 90% of the snippets posted in SO) ?
The answer to 1 would be true even after a reboot (the phone booting with wifi off) ?
The reason I ask is I need to get the list of the available access points periodically and I'd rather call getScanResults() at once, than WifiManager.startScan() and then getScanResults() if I really do not have to - as this involves acquiring wifi locks and the like and is rather subtle. I am not also sure how much do the API level and phone hardware come into play.
For a good discussion of difficulties see this answer

When wireless is disabled
getScanResults() will return null...
...even after a reboot (that's to be expected - this would be disputed if it did not return null in the first place)
When wireless is enabled
2.Surprisingly enough getScanResults() will return null after some time (on a Nexus One, Android 2.3.7, Cyanogen mod - but I suspect this is not really relevant). So yes, apparently one has to initiate a scan irrespective of the wireless status
I guess this is true also if the state is WIFI_STATE_DISABLING
I am still interested in the answer in the case wireless is enabled - in particular question 2, if the device is asleep. Google groups won't let me post (hint)

public List getScanResults ()
Added in API LEVEL 1
Return the results of the latest access point scan.
Returns
the list of access points found in the most recent scan. An app must hold ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission in order to get valid results.

Related

How to detect available carrier networks?

Is there any way in Android to detect all available carrier networks in the area. I tried to search it from connectivity manager and it seems it only returns active network info. I also tried the telephony manager and it only returns signals and neighbor info of the active carrier (e.g. other signals of same carrier). I would like to create an app that will scan for available cell networks in every country -- like in Settings -- to choose my network when roaming.
as far as i know that is not possible, because you can only get the cell info of your SIM carrier, but we have a new method on TelephonyManager called getAllCellInfo ().
The problem is that method its only available on API Level 17, only available on devices with Jelly Bean (4.2).
Check this link for more information.
Even the getAllCellInfo function will never report "all networks" that are in the air at your location, simply because the phone will only listen to / measure on the frequencies / networks that the current serving cell tells it to measure on. Normally this means that it will only measure (and be able to report cells) from the same network as the phone is currently using.
If the phone has lost coverage from its "home PLMN" (home or selected network) it will however periodically do measurements in other frequencies to try to get back to it's "favourite network".
To be able to get lists of all present networks in your area you need to have another kind of device for example a "scanner", which never locks on to any cell, but continuously scans many frequencies to find cells from any network and any radio access technology (GSM/WCDMA LTE for example) within these frequencies.
Or continuously press the "select network" function...
/ Kenneth

Android How to identify carrier on CDMA network?

Android provides the following method to determine the network operator:
http://developer.android.com/reference/android/telephony/TelephonyManager.html#getNetworkOperatorName()
However even the documentation specifically says:
Returns the alphabetic name of current registered operator.
Availability: Only when user is registered to a network. Result may be unreliable on CDMA networks (use getPhoneType() to determine if on a CDMA network).
The problem is that we need a reliable way to detect the carrier so we can identify the traffic source. Has anyone had a similar problem and if so, what is the best solution?
My phone is on Verizon Wireless. On a daily basis, I drive through areas where my phone is roaming and/or has poor reception. Using scripting layer for android, I will log the results of calling getOperatorName() once every ten minutes over the next week.
There is another method that might work in the android.telephony.cdma api. The documentation there is missing the reliability disclaimer. You would only get a Network ID instead of a name. Unfortunately, this requires API level 5 instead of 1 if that matters to you.
Logging the results of the getOperatorName() method yielded nothing special. When I had no service it consistently returned null and when I had service it consistently returned "Verizon Wireless." I'm sure that's not very helpful.
Edit: Addition and correction.
Added - Explanation of link
Corrected - API level 5 not 17
Edit 2: Test results
I am currently looking for a solution for this problem as well. According to this thread one could use CdmaCellLocation.getNetworkId and CdmaCellLocation.getSystemId. Since there are no CDMA networks in Germany, I am unable to check if this works...
You think maybe this was one precurser to Google pulling cdma support? Play within the frameworks or find you another playground is what I hear Google saying. Well that and the fact that carrier apps burned into roms have at times left gaping holes in security.
As to a possible answer to your question... from where are you able to pull info? APN settings might tell you or an assert to a known carrier line in build.prop could pull the info I might need for example. (I do the hobby roms). Then again if you physically inspect a phone, the carrier is usually branded ;) From what vantage are you pulling the info?
Rob

Difference between NetworkInfo.isRoaming() and TelephonyManager.isNetworkRoaming()

I'm trying to detect wether the device is roaming or not in my app and I've found these two methods:
NetworkInfo.isRoaming()
TelephonyManager.isNetworkRoaming()
Is there an essential difference between them or can I just choose one?
I think TelephonyManager.isNetworkRoaming()is 2G-related, whether NetworkInfo.isRoaming() is 3G-related - setting data-roaming on/off is a distinct option in the android-settings, so if it's off you still may get truefor GSM (TelephonyManager.isNetworkRoaming())

Android detect no data connection

I know there are a few threads on this topic but non of them seem to answer my question. I want to be able to detect when the device has no data connection. I have tried the NetworkInfo route checking if its null, isConnected(), isAvailable() etc. The problem im having is that these work fine (return false or null) when wifi or mobile network are disabled however when they are enabled but there is no signal they return true. Is there any way to detect no data connection due to no signal?
build reciver and catch broadcast
Intent action for network events in android sdk
You could try pinging google.com. If there's no response, you can be fairly sure that there's no connection (unless the user is in a country where it is blocked).
I use ConnectivityManager.getActiveNetworkInfo.isConnectedOrConnecting()
I just tested it 5 minutes ago to make sure, and if everything is working and I then walk away from my house until my router is no longer within range and the network strength indicator on the status bar shows no network, a call to isConnectedOrConnecting() from within an app returns false.
I take it that's not the behavior you are seeing?

Wifi reports as "enabled" even though it's not

I'm not sure if this is a Galaxy Tab specific issue or if I'm not utilizing some relevant method of the WifiManager library, but my application correctly reports that the Wifi is disabled at launch, but then as soon as I enable it, it deems itself as enabled, even though it's still in the process of connecting.
So, I have a thread in which I'm waiting for the enabled state
//at THIS line it claims to be WIFI_STATE_DISABLED so I turn it on with...
wifiManager.setEnabled(true);
//and at this line it reports as 3 (which according to the doc is WIFI_STATE_ENABLED, even though it clearly isn't
while(wifiManager.getWifiState() == WifiManager.WIFI_STATE_DISABLED || wifiManager.getWifiState() == WifiManager.WIFI_STATE_ENABLING){
but it never never enters the loop, it just jumps right past even though it is NOT enabled
I'm hoping there's some other mechanism that I'm missing, or maybe I'm misunderstanding what "enabled" means?
The WifiManager.WIFI_STATE_ENABLED only tells you, that the wifi device has been turned on. It does not tell you if a connection to a wireless network has been established.
Take a look at the android.net.ConnectivityManager.getActiveNetworkInfo(). This function will return a NetworkState. With the NetworkState.getState() function you can check if a connection is really available.

Categories

Resources