2017-02-28 3 views
2

J'ai une exigence comme j'ai besoin d'afficher une icône lorsque mon application ne fonctionnait pas sur le premier plan. Pour cela, j'ai besoin d'ajouter la vue au gestionnaire de fenêtres. est-il possible d'ajouter la vue au gestionnaire de fenêtre dans android tv.est-il possible d'ajouter une vue à WindowManager dans android TV

c'est le code i essayé

LayoutInflater inflater = LayoutInflater.from(getActivity()); 
     final View layout = inflater.inflate(R.layout.layout_show_on_top_of_view, null); 

     WindowManager.LayoutParams params = new WindowManager.LayoutParams(); 
     params.gravity = Gravity.TOP | Gravity.LEFT; 
     params.height = WindowManager.LayoutParams.WRAP_CONTENT; 
     params.width = WindowManager.LayoutParams.WRAP_CONTENT; 
     params.type = WindowManager.LayoutParams.TYPE_TOAST; 
     params.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE 
       | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE 
       | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON 
       | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN; 
     params.format = PixelFormat.TRANSLUCENT; 
     params.windowAnimations = 0; 
     final WindowManager mWindowManager = (WindowManager) 
       getActivity().getSystemService(Context.WINDOW_SERVICE); 
     mWindowManager.addView(layout, params); 
     layout.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View view) { 
       mWindowManager.removeView(layout); 
      } 
     }); 

j'ai essayé différents types aussi, mais il ne fonctionne pas.

+0

avez-vous trouvé la solution? – NehaK

+0

@NehaK J'ai beaucoup essayé mais je n'ai trouvé aucune solution pour cela. –

Répondre

1

Je pense que ce que vous voulez atteindre peut être fait avec une activité transparente, consultez cette autre question/réponse: Is it possible to draw overlay over any screen using 3rd party app in android TV?

+0

Mais par cette activité de retour d'activité transparente ira dans l'état d'arrière-plan, et ne fonctionne pas comme prévu. N'est-il pas possible via le service? – NehaK

+0

Vous pouvez recevoir la notification sur un service, puis démarrer une activité qui fonctionnerait. Aussi, je pense que démarrer une nouvelle activité d'une application en arrière-plan la mettra au premier plan. – shalafi