0

I am trying to turn on the gps automatically. But I can not find the solution for this. Now I am using like navigate to the settings page to turn on the GPS. In OLA cabs app gps is automatically on. I want to turn on the GPS location automatically like OLA cabs. I am using following code for switch on the GPS.

public void MessageNoGps(final Activity mActivity) {
        final AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
        builder.setMessage(mActivity.getString(R.string.gps_enable))
                .setCancelable(false)
                .setPositiveButton(mActivity.getString(R.string.yes),
                        new DialogInterface.OnClickListener() {
                            public void onClick(final DialogInterface dialog,
                                    final int id) {
                                mActivity
                                        .startActivity(new Intent(
                                                android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
                            }
                        })
                .setNegativeButton(mActivity.getString(R.string.no),
                        new DialogInterface.OnClickListener() {
                            public void onClick(final DialogInterface dialog,
                                    final int id) {
                                dialog.cancel();
                                mActivity.finish();
                            }
                        });
        final AlertDialog alert = builder.create();
        alert.show();
    }

Please let me know how to turn on the GPS automatically.

  • 2
    Possible duplicate of [How to turn on the GPS on Android](http://stackoverflow.com/questions/9928256/how-to-turn-on-the-gps-on-android) – 1615903 Nov 19 '15 at 12:25
  • @1615903.. Thanks for sharing the link. But how OLA activate the GPS? – Vijayadhas Chandrasekaran Nov 19 '15 at 12:35
  • Ok, just checked the Ola Cabs app - maybe you are looking for this question: http://stackoverflow.com/questions/29801368/how-to-show-enable-location-dialog-like-google-maps – 1615903 Nov 19 '15 at 12:43

1 Answers1

1

Ola Cabs is using the newly released Settings API to achieve this functionality. As per the new API the user is not required to navigate to the settings page to enable location services giving a seamless integration for the same. Please read below for more details:

enter link description here

Abhi
  • 3,012
  • 21
  • 14