简体   繁体   English

SYSTEM_ALERT_WINDOW 的运行时权限

[英]Runtime permission for SYSTEM_ALERT_WINDOW

I need to get the user permissions automatically for the following permissions while user opens the app for the first time当用户第一次打开应用程序时,我需要自动获取用户权限以获得以下权限

  1. Phone电话
  2. Call logs通话记录
  3. Always on top总在最前面

Phone is working fine.电话工作正常。 How to get the always on top permission如何获得始终处于最高权限的权限

MainActivity主要活动

protected void onCreate(Bundle savedInstanceState) {
    if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.SYSTEM_ALERT_WINDOW)
            != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.SYSTEM_ALERT_WINDOW}, 1);
    }
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

Manifest显现

<uses-permission android:name="android.permission.READ_CALL_LOG" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />

there is no runtime permission/dialog for this purpose, you have to pass user to app settings没有为此目的的运行时权限/对话框,您必须将用户传递给应用程序设置

public boolean checkStartPermissionRequest() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (!Settings.canDrawOverlays(this)) {
            Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
                Uri.parse("package:" + getPackageName()));
            startActivityForResult(intent, ACTION_MANAGE_OVERLAY_PERMISSION_REQUEST_CODE);
            return false; // above will start new Activity with proper app setting
        }
    }
    return true; // on lower OS versions granted during apk installation
}

more info HERE更多信息在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android SYSTEM_ALERT_WINDOW权限 - Android SYSTEM_ALERT_WINDOW permission 请求 SYSTEM_ALERT_WINDOW 权限后返回应用程序 - Return to app after requesting SYSTEM_ALERT_WINDOW permission 如何检查权限在Android Lollipop上授予SYSTEM_ALERT_WINDOW? - How to check permission SYSTEM_ALERT_WINDOW is granted on Android Lollipop? 如何在本机反应中删除 SYSTEM_ALERT_WINDOW android 权限 - How remove SYSTEM_ALERT_WINDOW android permission in react native Android13,SYSTEM_ALERT_WINDOW权限未勾选BroadcastReceiver - Android13, SYSTEM_ALERT_WINDOW permission not checked in BroadcastReceiver Android:SYSTEM_ALERT_WINDOW权限保护级别 - Android: SYSTEM_ALERT_WINDOW permission Protection level 如何访问SYSTEM_ALERT_WINDOW权限运行时间? - How to access SYSTEM_ALERT_WINDOW permission run time? SYSTEM_ALERT_WINDOW中的ListView - ListView in SYSTEM_ALERT_WINDOW API 26 上的 SYSTEM_ALERT_WINDOW PERMISSION 未按预期工作。 窗口类型 2002 的权限被拒绝 - SYSTEM_ALERT_WINDOW PERMISSION on API 26 not working as expected. Permission denied for window type 2002 通过Appop Denial错误授予SYSTEM_ALERT_WINDOW权限后,Android marshmallow - Android marshmallow after granting permission through Appop Denial error for SYSTEM_ALERT_WINDOW permission
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM