<span id="Label3"></p><span style="color:#ff0000"><span style="color:#ff0000">Monitor GPS</span></span>Permissions: <uses-permission android:name= "android.permission.ACCESS_FINE_LOCATION"/><br><br>Main program code and Comments:<br><pre name="code" class="java"><span style= "white-space:pre" ></span>/** * Monitor gps */private void Initgps () {locationmanager LocationManager = (locationmanager) This.getsystemservice (context.location_service);//determine If the GPS module is turned on, if not, turn on if (! locationmanager.isproviderenabled (android.location.LocationManager.GPS_PROVIDER)) {toast.maketext ( traindetailsactivity.this, "please Open gps", toast.length_short). show (); Alertdialog.builder dialog = new Alertdialog.builder (this);d ialog.setmessage ("please turn on gps");d Ialog.setpositivebutton (" OK ", new Android.content.DialogInterface.OnClickListener () {@Overridepublic void onClick (dialoginterface arg0, int Arg1) {//go to the phone settings screen, user settings Gpsintent intent = new Intent (settings.action_location_source_settings); Startactivityforresult (intent, 0); Return to the original interface});d Ialog.setneutralbutton ("cancel", new Android.content.DialogInterface.OnClickListener () {@ overridepublic void OnClick (dialoginterface arg0, int arg1) {arg0.dismiss ();}} );d Ialog.show ();} else {//eject Toast//toast.maketext (traindetailsactivity.this, "GPSIs-ready ",//toast.length_long). show ();////popup dialog//new alertdialog.builder (this). setmessage (" GPS are ready ")//. Setpositivebutton ("ok", null). Show ();}}</pre><br><br><p><p>Android Monitor GPs is turned on jump to set GPS</p></p></span>
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