【发布时间】:2017-06-21 17:23:52
【问题描述】:
我是 android 编程新手,我需要显示警报,以便用户在点击允许按钮时自动授予我的应用程序权限。
喜欢这个应用
但实际上我的代码会发出一条消息,只会将用户带到设置,以便他/她可以手动更改它,并不是每个人都知道如何手动进行
我怎样才能获得第一个警报,以便应用程序自动获得权限,而不是我目前将用户移动到设置页面并且他们必须手动完成的方式
这是我的代码
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();
}
【问题讨论】:
标签: android permissions location android-gps