Enable GPS programmatically Android (without navigating to the location settings)

前端 未结 2 822
半阙折子戏
半阙折子戏 2020-12-05 15:04

How to enable GPS programmatically, as it does happen in the official Google Maps app by just clicking on the \'turn on\' option on the pop up screen (without navigating to

2条回答
  •  难免孤独
    2020-12-05 15:43

    That's because they are using the Settings API in the play services as described in Commonsware's answer, which is a bit difficult. You are better off with the "old" method:

    Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
    startActivity(intent);
    

提交回复
热议问题