Network Management for Android

Source: Internet
Author: User
  1. /** 
  2. * Test connectivitymanager 
  3. * Connectivitymanager manages network connection-related operations. 
  4. * Telephonymanager manages information related to mobile phones and carriers, and wifimanager manages information related to wifi. 
  5. * To access the network status, you must first add the permission <uses-Permission Android: Name = "android. Permission. access_network_state"/> 
  6. * The networkinfo class contains a detailed description of the connection between Wi-Fi and mobile network modes. The State object obtained through its getstate () method represents 
  7. * The connection is successful or not. 
  8. */
  9.  Public VoidTestconnectivitymanager (){
  10. Connectivitymanager connmanager = (connectivitymanager)This
  11. . Getsystemservice (connectivity_service );
  12. // Obtain the networkinfo object that represents the networking status
  13. Networkinfo = connmanager. getactivenetworkinfo ();
  14. // Obtain whether the current network connection is available
  15. BooleanAvailable = networkinfo. isavailable ();
  16. If(Available ){
  17. Log. I ("Notification","The current network connection is available");
  18. }
  19. Else{
  20. Log. I ("Notification","The current network connection is available");
  21. }
  22. State state = connmanager. getnetworkinfo (connectivitymanager. type_mobile). getstate ();
  23. If(State. Connected = State ){
  24. Log. I ("Notification","GPRS network connected");
  25. }
  26. State = connmanager. getnetworkinfo (connectivitymanager. type_wifi). getstate ();
  27. If(State. Connected = State ){
  28. Log. I ("Notification","Wi-Fi network connected");
  29. }
  30. // Jump to the wireless network settings page
  31. Startactivity (NewIntent (Android. provider. settings. action_wireless_settings ));
  32. // Jump to the unlimited WiFi network settings page
  33. Startactivity (NewIntent (Android. provider. settings. action_wifi_settings ));
  34. }
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.