Android Network connection WiFi GPRS connection

Source: Internet
Author: User

 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.