PackageCom.example.androidday15_network1;Importandroid.app.Activity;ImportAndroid.content.Context;Importandroid.content.Intent;ImportAndroid.net.ConnectivityManager;Importandroid.net.NetworkInfo.State;ImportAndroid.os.Bundle;ImportAndroid.os.Handler;ImportAndroid.widget.TextView;ImportAndroid.widget.Toast;/**
Add Permissions <uses-permission android:name= "Android.permission.ACCESS_NETWORK_STATE"/>
* Network settings * through Connectivitymanager network Connection Manager to get the current device connection * MAMAGER.GETNETWROKINFO (connectivitymanager.type_mobile) *// Obtain the network information of the device by the type of information that is developed. GetState () Get the connection status of a network device * If not successful, use an intent to device network * This is a time-consuming operation, handled by a Handler, * new Handler () {* Hand Lemessage (Message msg) {* Intent Intent = new Intent (); * Intent.setaction ("Android.provider.Settings.ACT Ion_wireless_settings ")//Set mobile network * intent.setaction (" Android.provider.Settings.ACTION_WIFI_SETTINGS ") * STA Rtactivity (Intent); *} *}.sendemptymessagedelayed (int What, long ms); there is a high-speed browser engine WebKit built into the Android, enabling efficient web-side access and browsing. is encapsulated in the SDK as a webview for invocation. If you want to implement access to the Web page in Android, use Webviewwv.loadurl (info), load the string representation of urlwv.setwebviewclient (new Webviewclient ()), and use the local client to display the page. onbackpressed: Click the Back button*/ Public classMainactivityextendsActivity {/*** Network Connection Manager * * To get the current network connection status through this manager*/ PrivateConnectivitymanager Manager; PrivateTextView TV; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); TV=(TextView) Findviewbyid (r.id.tv); //Get managerManager =(Connectivitymanager) Getsystemservice (Context.connectivity_service); //GPRS Get network connection Status//Get Status connection information Mibilestate gprsstate =Manager.getnetworkinfo (connectivitymanager.type_mobile). GetState (); //Get WiFi statusstate wifistate =Manager.getnetworkinfo (Connectivitymanager.type_wifi). GetState (); //Determine network connectivity, no network if(!gprsstate.equals (state.connected) &&!wifistate.equals (state.connected)) {Toast.maketext ( This, "No network connection currently", 1). Show (); //jump to Network settings interface, delay jump NewHandler () { Public voidhandlemessage (android.os.Message msg) {Intent Intent=NewIntent (); //jump to the Network Settings screenintent.setaction (Android.provider.Settings.ACTION_WIRELESS_SETTINGS); //WiFi Setup Interface//intent.setaction (Android.provider.Settings.ACTION_WIFI_SETTINGS);startactivity (Intent); }; }.sendemptymessagedelayed (0, 4000); } }}
Android Network connection WiFi GPRS connection