Web development is a very important part of Android programming, and today we share with you some of the experience of Android Web development.
In this paper, the method of acquiring network link state by Android is illustrated by the example form. The specific contents are as follows:
As far as the current Android phone is concerned, there may be 5 network states:
----No network (this state may be due to phone downtime, network is not open, bad signal, etc.)
----Use WiFi access
----Cmwap (China Mobile agent)
----Cmnet Internet
----2G/3G/4G Internet
Many times we need to determine whether a user is opening a network setting, usually by Connectivitymanager classes to determine whether a network connection exists.
Get Network Status:
So how do you use this class? How do you interact with the user? The specific examples are as follows:
public class Mainactivity extends activity {
@Override
protected void onCreate (Bundle savedinstancestate) {
super.oncreate (savedinstancestate);
Setcontentview (r.layout.activity_main);
Connectivitymanager NW = (Connectivitymanager) this.getsystemservice (context.connectivity_service);
Networkinfo NetInfo = Nw.getactivenetworkinfo ();
Toast.maketext (mainactivity.this, "Current Network" +add (Netinfo.isavailable ()) + "," + "Network" +app (netinfo.isconnected ()) + "," + " Network Connection "+ADP (netinfo.isconnected ()), Toast.length_long). Show ()//give user prompt for network status
}
String Add (Boolean bl) {
String s = "not available";
if (bl==true) {
s= "available";
}
return s;
}
String app (Boolean bl) {
string s = "Not Connected";
if (bl==true) {
s= "connected";
}
return s;
}
string ADP (Boolean bl) {
string s = "does not exist! ";
if (bl==true) {
s= exists! ";
}
return s;
}
}
Certainly don't forget to get network permissions in the configuration file, the code is as follows:
<!--Get network permissions-->
<uses-permission
android:name= "Android.permission.ACCESS_NETWORK_STATE"
/ >
I hope the example described in this article will help you with your Android programming.