Android determines if GPS is enabled

Source: Internet
Author: User


Determine if mobile phone GPS is enabled
The following code is used to determine whether the mobile phone's GPS service is enabled. If so, the user is prompted that the GPS service has been enabled.

If the current GPS status is disabled, give the user a prompt, and then open the GPS settings interface, let the user change the GPS status to start.

Java code:

Private void opengpssettings ()
{
Locationmanager ALM =
(Locationmanager) This. getsystemservice (context. location_service );
If (ALM. isproviderenabled (Android. Location. locationmanager. gps_provider ))
{
Toast. maketext (this, "GPS is already on", Toast. length_short). Show ();
}
Else
{
Toast. maketext (this, "Please turn on GPS", Toast. length_short). Show ();
Intent myintent = new intent (settings. action_security_settings );
Startactivity (myintent );
}
}

 

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.