I am developing a kind of contact provider for Android users. The main function is that when the device receives a call (blocked or not blocked), a popup window with some information of the calling contact appears. The problem is that with versions below the Android 7.0 everything works perfectly but from Android 7.0 when the device is blocked and receives a call the popupwindow appears behind the call layout and therefore can not be seen until hang If someone could help me on how to make it appear in front of the call layout in Android 7.0 I would be very grateful.
pd. remember that below 7.0 does work for me, then the problem is from the new version 7.0
public class IncomingCallActivity extends Activity {
int mCurrentX = 0;
int mCurrentY = 500;
@Override
protected void onCreate(Bundle savedInstanceState) {
final LinearLayout fondo;
TextView text;
try {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_empty);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE |
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON |
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
LayoutInflater layoutInflater = (LayoutInflater) getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
final View popupView = layoutInflater.inflate(R.layout.layout_incoming_call, null);
Button button = (Button)popupView.findViewById(R.id.close_window);
text = (TextView) popupView.findViewById(R.id.text);
button.setText("CLOSE WINDOW");
final PopupWindow popupWindow = new PopupWindow(popupView, ViewGroup.LayoutParams.MATCH_PARENT, 300);
new Handler().postDelayed(new Runnable() {
public void run() {
popupWindow.showAtLocation(popupView, Gravity.NO_GRAVITY,mCurrentX,mCurrentY);
popupView.bringToFront();
}
}, 100);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
popupWindow.dismiss();
finish();
}
});
popupView.setOnTouchListener(new View.OnTouchListener() {
int orgX, orgY;
int offsetX, offsetY;
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
orgX = (int) (mCurrentX - event.getRawX());
orgY = (int) (mCurrentY - event.getRawY());
break;
case MotionEvent.ACTION_MOVE:
mCurrentX = (int) event.getRawX() + orgX;
mCurrentY = (int) event.getRawY() + orgY;
popupWindow.update(mCurrentX, mCurrentY, -1, -1, true);
break;
}
return true;
}
});
String number = getIntent().getStringExtra(
TelephonyManager.EXTRA_INCOMING_NUMBER);
text.setText("Incoming call from " + number);
} catch (Exception e) {
Log.d("Exception", e.toString());
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}