【发布时间】:2018-02-18 01:41:52
【问题描述】:
我不能允许其他应用程序的权限。它向我显示了允许权限的窗口,但我无法切换开关,它已被禁用。我检查了其他答案,但它对我没有帮助我使用了与其他讨论相同的解决方案,但它不起作用。
这里: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();
}
【问题讨论】:
-
This 可能会有所帮助。
-
@ADM 我已经在使用它当前位于 checkDrawOverlayPermission() 中。
标签: android android-permissions