Basic operations for the Android-location Services (Service) class

Source: Internet
Author: User

basic operations for Location Locator (service) classes


This address: Http://blog.csdn.net/caroline_wendy


Location services, you can determine the address of mobile devices, in the map-related services, often using GPS and mobile-related location services, GPS more accurate.

According to the common location service function, add network detection and WiFi detection, and start the relevant interface to test the function.


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. * * Location Service library: * Includes function: Determine whether to start the location service, network connection, wifi connection * page jump and location service settings interface, WiFi settings interface */public class Locationserviceutils {private    Static final String TAG = "Locationserviceutils"; /** * Determines whether to start the location service * * @param context Global Information interface * @return whether to start the location service */public static Boolean Isopenlocser        Vice (final context context) {Boolean Isgps = false;//Determine if GPS positioning starts Boolean isnetwork = false;//determine if network positioning is started if (context! = null) {Locationmanager Locationmanager = (locationmanager) context.get            Systemservice (Context.location_service); if (Locationmanager! = null) {//GPS satellite positioning, positioning level can be accurate to the street (through 24 satellite positioning, in outdoor and open location accurate, fast) Isgps = L OcAtionmanager.isproviderenabled (Locationmanager.gps_provider); A location determined by the WLAN or mobile network (3G/2G), also known as AGPS, assists with GPS positioning. Mainly used in indoor or shelter (complex or dense deep forest, etc.) dense place positioning) Isnetwork = locationmanager.isproviderenabled (locationmanager.network_provi            DER);            } if (Isgps | | isnetwork) {return true;    }} return false; /** * Determines whether to start all network connections, including WIFI and traffic * * @param context Global Information interface * @return whether to connect to network */public static bool EAN isnetworkconnected (Context context) {if (context! = null) {Connectivitymanager mconnectivitymanage            R = (Connectivitymanager) context.getsystemservice (Context.connectivity_service);            Networkinfo mnetworkinfo = Mconnectivitymanager.getactivenetworkinfo ();            if (mnetworkinfo! = null) {return mnetworkinfo.isavailable ();    }} return false;     }/** * Determines whether to start the 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 Location Service Interface * * @param context Global Information interface */public static void Gotolocservicesettings (Context cont        EXT) {Final Intent Intent = new Intent (Android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);        Intent.setflags (Intent.flag_activity_new_task);    Context.startactivity (Intent); }/** * Jump WiFi Service Interface * * @param context Global Information interface */public static void Gotowifiservicesettings (context C        Ontext) {final Intent Intent = new Intent (settings.action_wifi_settings);        Intent.setflags (Intent.flag_activity_new_task);    Context.startactivity (Intent); }}


Tool classes can be used directly.

Basic operations for the Android-location Services (Service) class

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.