I am gonna to implement a application, to list all the networks and manually select one of them( similar to the stock one ), can some one what kind of api can I use or what documentation should I refer to , or any reference sites ?
Thanks in advance !
You have to use ConnectivityManager
The primary responsibilities of this
class are to:
Monitor network connections (Wi-Fi, GPRS, UMTS, etc.)
Send broadcast intents when network connectivity changes
Attempt to "fail over" to another network when connectivity to a network
is lost
Provide an API that allows applications to query the
coarse-grained or fine-grained state
of the available networks
Get an instance of this class by calling:
Context.getSystemService(Context.CONNECTIVITY_SERVICE).
Maybe you will have a look at NetworkInterface and its enumeration , too
Related
The method to getConfiguredNetworks has now been deprecated in Android Q. I was using this feature in order to determine whether a Wifi network has any security such as WifiConfiguration.KeyMgmt.WPA_EAP. All of these are now deprecated and i am not sure whether there is any alternative. Google suggests to use WifiNetworkSpecifier.Builder#build() but this is for connecting to new network, not for my use case.
WiFi scanning allows you to get the list of networks in range.
Then you can parse ScanResult.capabilities, which should - among others - contain the encryption info of the network (WPA/WPA2/etc).
Granted, it would be more convenient to have a proper object rather than a string, but here we are.
How can I programmatically check that internet access in a android device is only over Wi-Fi and not over Packet Data connections like UMTS EDGE or GPRS ?
if you want your app to only use one particular type of data connection, you can form if/else logic and use check for mobile-network-access and wifi-access and give command accordingly
you can refer to mobile-network-access and wifi-access questions of stackoverflow for check on connection availability
I'm developping an app which may send sensitive data and I want to be sure that i don't send them on a public or weak protected network.
That's why I'd like to get the current security used on wifi network on Android.
I found this post but I'm not sure of the accuracy of the solution.
Indeed, the allowedKeyManagement method seems to return the supported protocols, but it's not explicitely said to return the current active protocol beeing used.
Is there a sure way to get the effective protection used on the cirrent wifi network ?
Thanks
I can suggest one method
Get list of all configured network using getConfiguredNetworks API
Loop through all entries and find the current Network using WifiConfiguration.status API. The status should be CURRENT for current network
For that current network, get the allowedKeyManagement and check that it is not NONE.
In my app I want to change the phone type (GSM/CMDA).
getPhoneType() method in TelephonyManager
returns 1 (PHONE_TYPE_GSM)
or 2 (PHONE_TYPE_CDMA).
I can change this manually through phone
menu - Networks - Mobile Networks - Network Type ()
AUTO/GSM/CDMA.
Can I change this programmatically?
In Settings.Secure, you have NETWORK_PREFERENCE which is described as:
User preference for which network(s) should be used. Only the connectivity service should touch this.
This leads you to ConnectivityManager which looks like it is only for data connection, so all the above information really is useless, but good to be aware of.
And in TelephonyManager There is no set method, so the only thing that may work is if you look at internal and hidden methods.
I'm making an app that is essentially a web form. I fill it out and send it to a website to be processed. But I only want it to send the data when connected to wifi.
I was thinking of putting the data into a tinyDB then running a check for wifi immediately. If connected it would submit the form and delete the db entry. I'd probably also run a check when the app is loaded and closed. It's important that I don't lose the data.
Is there a better way to do this?
if the form is small, you may not even need a db, you could just use SharedPreferences
http://developer.android.com/guide/topics/data/data-storage.html#pref , unless you have multiple rows of the user answering again and again then this might not be the best solution
here's some network check code if you need it
ConnectivityManager manager =(ConnectivityManager)activityOrContext.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = manager.getActiveNetworkInfo();
if(info==null || !info.isConnected()){
return false;// network not active
}
not sure if you need this, you may already know how to do this or have it figured out
Have a look at my question How to respect network use settings in Android. Some of the answers demonstrate how to check the network type.
You can prompt the user to ask him if he wants to enable Wifi, and then you can enable it from code. Take a look at WifiManager class.