【问题标题】:How to create a service with addView() using WindowManager in Android如何在 Android 中使用 WindowManager 使用 addView() 创建服务
【发布时间】:2019-10-14 12:50:52
【问题描述】:

我已经浏览了许多在线可用的解决方案,但我觉得不太合适。

基本上我想通过服务来利用以下参数

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON|
            WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD|
            WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED|
            WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);

我浏览了其中一个参考资料 are there anybody know how to getWindow() in service on android?

if(mConfiguration.orientation==Configuration.ORIENTATION_LANDSCAPE){
    mLayoutParams.screenOrientation=Configuration.ORIENTATION_PORTRAIT;
}
mLayoutParams.softInputMode=WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN;

mLayoutParams.gravity = Gravity.TOP|Gravity.CENTER; 
int flag=0
            |WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN
            |WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
            |WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM
            ; 
mLayoutParams.flags=flag;

mWindowManager.updateViewLayout(mRootView, mLayoutParams);

以上代码中如何在服务中使用rootview?

期待很快收到您的来信。

【问题讨论】:

    标签: android service rootview


    【解决方案1】:

    变量mRootView 指的是添加到WindowManager 的视图。

    假设您已将视图 myView 添加到 WindowManager,如下所示:

    class MyService extends Service
    {
        private View myView;
    
        ...
        myView = new View(context);
        mWindowManager.addView(myView, mLayoutParams);
        ...
    }
    

    现在您可以使用updateViewLayout 方法更新myView 的LayoutParams:

    mWindowManager.updateViewLayout(myView, mLayoutParams)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-11-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-23
      • 1970-01-01
      相关资源
      最近更新 更多