How do I add a popup dialog over the call screen? I'll be using the BroadcastReceiver
to listen for incoming calls and show it. I need an idea about how to write an activity that allows a dialog over an incoming call. Also, how do I make the dialog movable to any part of the screen? I already have the BroadcastRceiver
implemented and performing other functions, so I could just use an intent and start the activity from this BroadcastRceiver
Asked
Active
Viewed 895 times
1

Slay
- 730
- 1
- 7
- 18
2 Answers
0
start an activity, then use AlertDialog Builder from that activity to prompt a dialog
set custom view to customize the dialog appearence

Patrick Chan
- 1,019
- 10
- 14
-
How do I make the dialog movable over the call screen? And I'd also like to have it cancelled by dragging it out of the screen. – Slay Dec 07 '14 at 11:22
-
1you can refer to this thread about creating modal overlay http://stackoverflow.com/questions/4481226/creating-a-system-overlay-window-always-on-top – Patrick Chan Dec 07 '14 at 11:31
-
Thanks that helps. But how do I make it floatable so I can drag it anywhere on the screen? – Slay Dec 07 '14 at 11:43
-
once a system overlay is created on screen, you can setOnTouchListener on the layout container (not the buttons). Check the action in onTouch(), see whether it's MotionEvent.ACTION_DOWN, ACTION_MOVE or ACTION_UP, and determine the x y of the system overlay – Patrick Chan Dec 07 '14 at 12:04
-
Could you provide an example? I can't wrap my head around an activity having only a dialog box. What kind of XML layout would it use? No hurries. – Slay Dec 07 '14 at 12:57
0
Try this
AlertDialog.Builder builder = new AlertDialog.Builder(context.getApplicationContext());
LayoutInflater inflater = LayoutInflater.from(context);
View dialogView = inflater.inflate(R.layout.caller_dialog, null);
ImageView button = dialogView.findViewById(R.id.close_btn);
builder.setView(dialogView);
final AlertDialog alert = builder.create();
alert.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
alert.getWindow().setType(WindowManager.LayoutParams.TYPE_PHONE);
alert.setCanceledOnTouchOutside(true);
alert.show();
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
Window window = alert.getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
window.setGravity(Gravity.TOP);
lp.copyFrom(window.getAttributes());
//This makes the dialog take up the full width
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
window.setAttributes(lp);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//close the service and remove the from from the window
alert.dismiss();
}
});

Karmelina Michael
- 182
- 1
- 7