I am new to android programming and I need to display an alert so that user give permission to my app automatically when he/she clicks on the allow button.
Like this app
but actually my code does a message that will just take the user to the setting so he/she can change it manually, and not everyone know how to do it manually
how can I get the first alert so that the app gain permission automatically instead of my current way where it just move the user to the setting page and they have to do it manually
here is my code
public void showSettingsAlert() {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(_activity);
alertDialog.setTitle("GPS Settings");
alertDialog.setMessage("GPS is not enabled. Do you want to go to settings menu ?");
alertDialog.setPositiveButton("Settings",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(
Settings.ACTION_LOCATION_SOURCE_SETTINGS);
_activity.startActivity(intent);
}
});
alertDialog.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
alertDialog.show();
}