Android and androidadt

Source: Internet
Author: User

Android and androidadt
Basic operations of the Location Service class


Address: http://blog.csdn.net/caroline_wendy


Location Service)You can determine the address of a mobile device, which is often used in map-related services.GPS and mobileGPS is more accurate.

Based on common positioning service functions, addNetwork DetectionAndWi-Fi detection, AndStart the system settings pageFunction for testing.


Code:

Import android. content. context; import android. content. intent; import android. location. locationManager; import android.net. connectivityManager; import android.net. networkInfo; import android.net. wifi. wifiManager; import android. provider. settings;/*** Created by wangchenlong on 14-11-17. ** locating service Library: * includes functions: determines whether to start locating service, network connection, and wi-fi connection * page Jump-> locating service setting interface, WIFI setting interface */public class LocationServiceUtils {private st Atic final String TAG = "LocationServiceUtils "; /*** determine whether to start the positioning service ** @ param context global information interface * @ return whether to start the positioning service */public static boolean isOpenLocService (final Context context) {boolean isGps = false; // determines whether the GPS Positioning starts boolean isNetwork = false; // determines whether the Network Positioning starts if (context! = Null) {LocationManager locationManager = (LocationManager) context. getSystemService (Context. LOCATION_SERVICE); if (locationManager! = Null) {// positioning by GPS satellite, the positioning level can be precise to the street (positioning by 24 satellites, accurate and fast in outdoor and empty places) isGps = locationManager. isProviderEnabled (LocationManager. GPS_PROVIDER); // a location (also known as AGPS) determined by a WLAN or mobile network (3G/2G) to assist in GPS positioning. IsNetwork = locationManager. isProviderEnabled (LocationManager. NETWORK_PROVIDER);} if (isGps | isNetwork) {return true ;}} return false;}/*** determine whether to start all network connections, including WIFI and traffic ** @ param context global information interface * @ return whether to connect to the network */public static boolean isNetworkConnected (Context context) {if (context! = Null) {ConnectivityManager mConnectivityManager = (ConnectivityManager) context. getSystemService (Context. CONNECTIVITY_SERVICE); NetworkInfo mNetworkInfo = mConnectivityManager. getActiveNetworkInfo (); if (mNetworkInfo! = Null) {return mNetworkInfo. isAvailable () ;}} return false ;} /*** determine whether to enable WIFI connection ** @ param context global information interface * @ return whether to connect to WIFI */public static boolean isWifiConnected (Context context) {if (context! = Null) {WifiManager wifi = (WifiManager) context. getSystemService (Context. WIFI_SERVICE); if (wifi! = Null) {return wifi. isWifiEnabled () ;}} return false;}/*** jump to the positioning service interface ** @ param context global information interface */public static void gotoLocServiceSettings (Context context) {final Intent intent = new Intent (android. provider. settings. ACTION_LOCATION_SOURCE_SETTINGS); intent. setFlags (Intent. FLAG_ACTIVITY_NEW_TASK); context. startActivity (intent);}/*** jump to the WIFI service interface ** @ param context global information interface */public static void gotoWifiServiceSettings (Context context) {final Intent intent = new Intent (Settings. ACTION_WIFI_SETTINGS); intent. setFlags (Intent. FLAG_ACTIVITY_NEW_TASK); context. startActivity (intent );}}


Static Methods of tool classes can be used directly.





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.