Android Preferred Network List - android

I was under the impression that wifiManager.getConfiguredNetworks() returns the PNL of the current device, however when I click on - forget network, wifiManager.getConfiguredNetworks() still keeps that network but just removes the connection details(like security, password etc.)
Is there anyway knowing which SSID(or BSSID) is actually in PNL? (i.e my device can automatically connect to it)

I found out that this problem appeared only on specifics networks, while in others clicking on forget network actually removes the network from wifiManager.getConfiguredNetworks().
I also found out that the only things different are allowedKeyManagement.cardinality and LinkProperties (which is hidden on Android), so I used an if statement on the WifiConfiguration(=configuredNetwork):
if(configuredNetwork.allowedKeyManagement.cardinality()==1)
wifiManager.removeNetwork(configuredNetwork.networkId);
wifiManager.saveConfiguration();
break;
And for some reason it worked. If anyone have an idea whats cardinality stands for or have a better way of doing this please share.

Related

WiFi suggestion API fail on Android

I've been trying to use the new Android WiFi Suggestion API with the code taken exactly from the example, but each time I try to connect to a network, when I call wifiManager.addNetworkSuggestions(suggestionsList) I get status 3 in response, which (according to this site) means IP provision failure. What does that mean? How can I handle that?
My app has all the required permissions and even some more (CHANGE_WIFI_STATE, ACCESS_WIFI_STATE, INTERNET, ACCESS_FINE_LOCATION, CHANGE_NETWORK_STATE, ACCESS_NETWORK_STATE), and the location is turned on. I tried with a few WiFi networks (all are visible in the WiFi settings), but still got the same IP provisioning error.
Had the same issue and found it quite confusing because status = 3 can mean two things: STATUS_SUGGESTION_APPROVAL_REJECTED_BY_USER or STATUS_NETWORK_SUGGESTIONS_ERROR_ADD_DUPLICATE.
In my case it was the latter. Basically the suggestion is remembered once submitted. I solved this by removing my suggestion before it's added:
wifiManager.removeNetworkSuggestions(suggestions)
val status = wifiManager.addNetworkSuggestions(suggestions)

Read Preferred Network Type Setting

I am trying to read the Preferred network type setting from the device. But nowhere android API's are available.
Use case:
Trying to read the Preferred network type and connected network type so that if the device has LTE enabled and the user is forcefully switched back to the lower network(3G,2G); then there should be a notification sent to the user.
I have checked the system setting code, But it's deprecated.
Settings.Secure.getString(getApplicationContext().getContentResolver(),
Settings.System.NETWORK_PREFERENCE);
Is there any alternate way to read the system secured settings(By reflection?).
And Also is it possible to write back the setting with the user permission?
Help is much appreciated.
I think the right code is:
Settings.Global.getString(context.getContentResolver(),Settings.Global.NETWORK_PREFERENCE)

How to calculate when the network card opens a connection on Android

I am trying to figure out if there is a way to know when an app opens an internet connection and thus wakes up the network card.
So for example, I have the phone off and I decide to search http://www.cnn.com
In this case, lets imagine that no background data is going on from any app, so the connection is IDLE at the time I call the website. I want to know when the network card opened the connection to load the page.
I have found no APIs for this. Originally I was looking at the TelephonyManager which has different states of the network card (DORMANT, INOUT, NONE, etc), but I found my phone never goes to dormant, I believe this is due to fast dormancy. I have also been looking at linux filesystem files that might contain this information from the driver, but I have found none.
I read this nice article from ATT which explains about mobile networks
http://www.research.att.com/articles/featured_stories/2011_03/201102_Energy_efficient?fbid=xEv4RTIfUL9
Thanks.
Ok so the answer is to use the SignalStrength class and the PhoneStateListener's onSignalStrengthsChanged in order to measure the radio signal. This helps detect when a connecdtion is made. Referenced from ATT's ARO app:
https://developer.att.com/application-resource-optimizer
http://developer.android.com/reference/android/telephony/SignalStrength.html
http://developer.android.com/reference/android/telephony/PhoneStateListener.html#onSignalStrengthsChanged(android.telephony.SignalStrength)

Enable 3G and WiFi Simultaneously

Does anyone know if its possible (programatically) to enable both 3G and WiFi to be used simultaneously, both receiving and sending packets?
I have seen various other questions on here, but with the Tethering ability inside Android now, I was wondering if this is a possibility? This has to be on a standard/stock device, and no modifications via root to the OS.
Thanks
Adam
I don't believe it is, as soon as wifi is turned on, 3g will automatically disconnect. As far as I know there is no way round it.
The only way you can achieve this is by using a APN name with the HttpConnection. This is possible in Java ME, Please visit this answer, however i have never tried it.
You need to check for the active connection, if not active first one the switch to the next connection.
public void shutup(){
SuDroid cmd = new SuDroid();
cmd.sh.runWaitFor("svc wifi enable");
cmd.sh.runWaitFor("svc data enable");
cmd.sh.runWaitFor("svc data prefer");
}
Using SuDroido

Change network selection mode programmatically

I'm trying (wondering if it's even possible) to write an app, that would change the network selection mode automatically, based on some criteria. E.g. change the network operator from Vodafone to T-Mobile (assuming that the SIM card registration will succeed, but I'm not worried about it atm)
Unfortunately, I can't seem to find any way in the API to do it. Anyone has any idea?
I assume, since it's not in the public APIs, there might still be a way to do it, if the phone is rooted. Is that true? If so, where should I look?
Thanks in advance
Sorry but you can't.
You can have a look into the TelephonyManager .
You can know the current operator: getSimOperator(Name) / getNetworkOperator(Name).
You can also check this thread saying "I learn that for the sake of security there aren't any public APIs to manage this so the only option is to send the user to the system PreferenceScreen within my app."
How about using android.telephony.CarrierConfigManager? I read about it on https://developer.android.com/reference/android/telephony/CarrierConfigManager.html and it seems to allow you to change alot of carrier-specific parameters, although the app must be signed with the certificate that has a matching signature to one on the SIM, so it can usually only be implemented by the carrier issuing the SIM. See also https://source.android.com/devices/tech/config/carrier.
I havent found an actual method to actively switch carrier, but if anywhere, I'd expect it to be there.

Categories

Resources