How I can know if a view is being displayed before adding with WindowManager? I need put a overlay in native Dialer but sometimes the native dialer put above mi custom view, I solved this by adding the element several times with WindowManager but sometimes the view is displayed twice.
Thanks!!
private void callStartIncomingCallScreen(Context context, String incomingNumber) {
startIncomingCallScreen(context, incomingNumber);
Timer timer = new Timer();
for (int i = 0; i < 2; i++) {
timer.schedule(new StartIncomingCallScreenTimerTask(context, incomingNumber), 100 * i);
}
}
class StartIncomingCallScreenTimerTask extends TimerTask {
private Context context;
private String incomingNumber;
StartIncomingCallScreenTimerTask(Context context, String incomingNumber) {
this.context = context;
this.incomingNumber = incomingNumber;
}
public void run() {
Intent intent = new Intent(context, IncomingCallGuiService.class);
context.startService(intent);
}
}
And in the IncomingCallGuiService i add the view like this:
final LayoutParams params = new LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT,
LayoutParams.TYPE_SYSTEM_ALERT,
LayoutParams.FLAG_NOT_FOCUSABLE | LayoutParams.FLAG_NOT_TOUCH_MODAL,
PixelFormat.TRANSLUCENT);
WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
// add the overlay
wm.addView(view, params);
You can check it with the view that you inflate. You can use view.isShown()
for check it. When you add the view with windowManager.addView(yourView)
this return true when you call isShown()
.
Hope it helps you.