我是android编程的新手,我需要显示警报,以便用户在点击允许按钮时自动授予我的应用程序权限。显示允许应用程序访问设备的位置
喜欢这个程序
但实际上我的代码确实的消息,这将只是把用户的设置,这样他/她可以手动更改它,而不是每个人都知道该怎么做手工
我怎样才能得到第一个警报,这样该应用增益权限自动代替我现在的方式它只是将用户移动到设置页面,他们甲肝E要做到这一点手动
这里是我的代码
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();
}
最简单的解决方案http://stackoverflow.com/a/40462527/1677824 – Akhil