Si non è possibile ottenere una finestra in un servizio. Ma tu puoi usare WindowManager per aggiungere una vista (root) come già fatto.
E È inoltre possibile aggiornare la vista attraverso updateViewLayout, è possibile modificare lo stato della finestra (tipo di finestra, bandiera, x, y, w, h, gravità, ecc ...) come sotto i codici.
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);
I servizi non dispongono di un'interfaccia utente. Cosa stai cercando di realizzare? –
So che il servizio non può avere un'interfaccia utente. Ma l'ho fatto usando addView() && surfaceView. –
Questo in realtà non crea un'interfaccia utente; crea solo un paio di oggetti View. Ripeterò la mia domanda: cosa stai effettivamente cercando di realizzare? –