1. 程式人生 > >Android之獲取動態懸浮窗許可權

Android之獲取動態懸浮窗許可權

需要兩步:

一、在清單配置檔案中宣告許可權:

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

二、程式碼申請許可權:

private static final int REQUEST_OVERLAY = 4444;

private void requestOverlayPermission() {
        if (Build.VERSION.SDK_INT >= 23) {
            if (!Settings.canDrawOverlays(ActivateActivity.this)) {
                Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
                        Uri.parse("package:" + getPackageName()));
                startActivityForResult(intent, REQUEST_OVERLAY);
            } else {
                
            }
        }
    }