how to turn on Location without permission or Alert in android studio

I wanna to make location Turn on every time i want With Socket.
my problem is what permission should i get of user in first open app .
i dont want show location Alert Dialog for Accept or Delince, just i want one Accept until user uninstall app.
this is my code with Alert dialog

 final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage("لطفا دسترسی به مکان خود را فعال نمایید.")
            .setCancelable(false)
            .setPositiveButton("باشه", new DialogInterface.OnClickListener() {
                public void onClick(final DialogInterface dialog, final int id) {
                    startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
                }
            })
            .setNegativeButton("نه", new DialogInterface.OnClickListener() {
                public void onClick(final DialogInterface dialog, final int id) {
                    dialog.cancel();
                }
            });
    final AlertDialog alert = builder.create();
    alert.show();

Leave a Reply

avatar
  Subscribe  
Notify of