I am trying to enable gps automatically. But I can not find a solution for this. Now I use as a transition to the settings page to enable GPS. In OLA cabins, the gps application automatically turns on. I want to automatically turn on the GPS location, like an OLA cab. I use the following code to enable 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 GPS automatically.
source
share