How to ask user to enable GPS at the launch of application?

前端 未结 5 774
我在风中等你
我在风中等你 2020-12-31 10:49
private void turnGPSOn(){
String provider = Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);

if(!provider.contains(\"gps         


        
5条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-31 11:09

    public void showSettingAlert()
        {
            AlertDialog.Builder alertDialog = new AlertDialog.Builder(context);
            alertDialog.setTitle("GPS setting!");
            alertDialog.setMessage("GPS is not enabled, Do you want to go to settings menu? ");
            alertDialog.setPositiveButton("Setting", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                    context.startActivity(intent);
                }
            });
            alertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            });
            alertDialog.show();
        }
    

提交回复
热议问题