【问题标题】:I can't allow overlay permission for my app我的应用不允许覆盖权限
【发布时间】: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


【解决方案1】:

对于搜索这个的后代,我遇到了同样的问题。问题是我不假思索地请求了权限的名称Manifest.permission.SYSTEM_ALERT_WINDOW,而不是值android.permission.SYSTEM_ALERT_WINDOW。由于清单也未在此处发布,因此这可能与 OP 遇到的问题相同。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-18
    • 1970-01-01
    • 1970-01-01
    • 2014-03-01
    相关资源
    最近更新 更多