我无法允许其他应用获取权限。它向我显示允许权限的窗口,但我无法切换开关,它被禁用。我检查了其他答案,它没有帮助我,我使用了与其他讨论相同的解决方案,但它不起作用。
此处:screen shot of the disabled swtich for permission
这是我的代码:
单击按钮时,将调用launchMainservice
btntest.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
hours = hours*3600000;
mins = mins*60000;
duration = hours+mins;
Toast.makeText(Main2Activity.this,"duration: "+duration,LENGTH_LONG).show();
StartService(duration);
launchMainService();
btntest.setClickable(false);
}
});
launchMainService():
public void launchMainService() {
if (Settings.canDrawOverlays(this)) {
Toast.makeText(this,"service is working",Toast.LENGTH_LONG).show();
Intent svc = new Intent(this, Service2.class);
startService(svc);
}
else {
Toast.makeText(this,"check permission",Toast.LENGTH_LONG).show();
checkDrawOverlayPermission();
}
}
public final static int REQUEST_CODE = 10101;
public void checkDrawOverlayPermission() {
if (!Settings.canDrawOverlays(this)) {
Toast.makeText(this,"setting another permission",Toast.LENGTH_LONG).show();
Intent intent123 = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName()));
startActivityForResult(intent123, REQUEST_CODE);
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE) {
Toast.makeText(this,"request code received",Toast.LENGTH_LONG).show();
// Double-check that the user granted it, and didn't just dismiss the request
if (Settings.canDrawOverlays(this)) {
launchMainService();
}
else {
Toast.makeText(this, "Sorry. Can't draw overlays without permission...", Toast.LENGTH_SHORT).show();
}
}
Toast.makeText(this,"failed to receive request code",Toast.LENGTH_LONG).show();
}
答案 0 :(得分:0)
对于子孙后代,我遇到了同样的问题。问题是我无意中请求了权限的名称Manifest.permission.SYSTEM_ALERT_WINDOW
,而不是值android.permission.SYSTEM_ALERT_WINDOW
。由于清单也未在此处发布,因此很可能是OP遇到的相同问题。