Android 如何在奥利奥的锁屏上绘制视图?

Android 如何在奥利奥的锁屏上绘制视图?,android,lockscreen,android-windowmanager,layoutparams,android-layoutparams,Android,Lockscreen,Android Windowmanager,Layoutparams,Android Layoutparams,这是我的密码。我正试图在锁屏上画一个视图。它在android 7.1上运行得非常好,但当我在oreo上运行它时,它就不工作了(视图不能出现在锁定屏幕上,但当你解锁屏幕时,视图出现,服务停止) 请检查此代码。有什么问题吗? 提前感谢。从API 26开始,android不允许在锁屏和通知托盘顶部绘图。Medical id和TrueCaller应用程序正在这样做,它们针对新的API。我不知道怎么办。 @Override public int onStartCommand(Intent origInte

这是我的密码。我正试图在锁屏上画一个视图。它在android 7.1上运行得非常好,但当我在oreo上运行它时,它就不工作了(视图不能出现在锁定屏幕上,但当你解锁屏幕时,视图出现,服务停止)

请检查此代码。有什么问题吗?
提前感谢。

从API 26开始,android不允许在锁屏和通知托盘顶部绘图。

Medical id和TrueCaller应用程序正在这样做,它们针对新的API。我不知道怎么办。
@Override
public int onStartCommand(Intent origIntent, int flags, int startId) {
    if (windowParams == null) {
        windowParams = new WindowManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, 65794, -2);
        if (origIntent != null) {
            demo = origIntent.getBooleanExtra("demo", false);
            windowParams.type = origIntent.getBooleanExtra("demo", false) ? WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY : Utils.isSamsung(getApplicationContext()) ? WindowManager.LayoutParams.TYPE_TOAST : WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
        } else
            windowParams.type = Utils.isSamsung(getApplicationContext()) ? WindowManager.LayoutParams.TYPE_TOAST : WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
        if (prefs.orientation.equals("horizontal"))
            //Setting screen orientation if horizontal
            windowParams.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
        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()));
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                if (Utils.doesIntentExist(this, intent))
                    startActivity(intent);
                return super.onStartCommand(origIntent, flags, startId);
            }

        windowManager.addView(frameLayout, windowParams);
        if (prefs.homeButtonDismiss)
            samsungHelper.startHomeButtonListener();
        raiseToWake = origIntent != null && origIntent.getBooleanExtra("raise_to_wake", false);
        if (raiseToWake) {
            final int delayInMilliseconds = 10000;
            UIHandler.postDelayed(() -> {
                stayAwakeWakeLock.acquire();
                stayAwakeWakeLock.release();
            }, 100);
            UIHandler.postDelayed(() -> {
                turnScreenOff();
                stoppedByShortcut = true;
                stopThis();
                Utils.logDebug(MAIN_SERVICE_LOG_TAG, "Stopping service after delay");
            }, delayInMilliseconds);
        }
    }
    return super.onStartCommand(origIntent, flags, startId);
}
 private void showBlackScreen(boolean show) {
    if (blackScreenParams == null) {
        blackScreenParams = new WindowManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, 65794, -2);
        blackScreenParams.type = Utils.isSamsung(getApplicationContext()) ? WindowManager.LayoutParams.TYPE_TOAST : WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
    }
    if (blackScreen == null)
        blackScreen = new FrameLayout(this);
    blackScreen.setBackgroundColor(Color.BLACK);
    blackScreen.setForegroundGravity(Gravity.CENTER);
    try {
        if (show) {
            if (!blackScreen.isAttachedToWindow())
                windowManager.addView(blackScreen, blackScreenParams);
        } else if (blackScreen.isAttachedToWindow())
            windowManager.removeView(blackScreen);
    } catch (IllegalStateException ignored) {
    }
}