2011-12-14 316 views
16

我使用WindowManager做了一個沒有活動的視圖。有沒有人知道如何getWindow()在Android上的服務?

,但我必須要改變的視圖狀態像下面

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
WindowManager.LayoutParams.FLAG_FULLSCREEN); 

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN, WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); 

但getWindow()的服務無法使用。

有沒有辦法?

+0

服務沒有UI。你想達到什麼目的? – 2011-12-14 05:04:48

+0

我知道服務不能有UI。 但我通過使用addView()&& surfaceView。 – 2011-12-14 06:25:35

+1

這實際上並不創建用戶界面;它只是創建了幾個View對象。我會重複我的問題:你究竟想要完成什麼? – 2011-12-14 06:32:23

回答

1

按服務沒有用戶界面,你必須從它開始活動getWindow()屬性..

要麼做一個透明的活動或剛開始活動,getWindow(),並立即完成它。我認爲你必須做出一個透明的活動。 (這是我的個人意見)

0

你正在努力做的事情,我收集,是有服務的信號,應該在活動的外觀上作出改變。做到這一點的方法是讓服務使用Context.sendBroadcast(Intent)來廣播意圖,並讓您的活動在onReceive方法中響應。 this thread中的接受答案有關於如何設置的更多詳細信息。

6

不能得到一個服務窗口。但你可以使用WindowManager添加一個視圖(根),你已經做了。

你也可以通過updateViewLayout更新視圖,你可以改變你的窗口的狀態(窗口類型,標誌,x,y,w,h,重力等),就像下面的代碼一樣。

private WindowManager mWindowManager; 
private WindowManager.LayoutParams mLayoutParams; 
.......... 

//let's assume that an event occurred 
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); 
相關問題