2

We're using an android application to do some assessments, when an assessor arrives on site they need to login with the office on the call. Theres a reference number I'd really like to be able to keep on the phone display once they ring in.

What would be perfect is a dialog that says the number on top of the dialer screen.

I've tried to do this, but it just overtakes the dialog and shows the calling screen. Is there anyway to push the dialer to the background and continue to show the user the dialog?

Heres what I have so far:

public void makecall(View view){ 
    try {
        Intent callIntent = new Intent(Intent.ACTION_CALL);
        callIntent.setData(Uri.parse("tel:NUMBER"));
        startActivity(callIntent);
        Toast.makeText(getApplicationContext(), "TEST",Toast.LENGTH_LONG).show(); 
        AlertDialog.Builder adb = new AlertDialog.Builder(this); 
        adb.setTitle("Alert"); 
        adb.setMessage("Client Reference Blah Blah");
        adb.setPositiveButton("Ok", new DialogInterface.OnClickListener() { 
            public void onClick(DialogInterface dialog, int id) { 

            } 
        });
        adb.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { 
            public void onClick(DialogInterface dialog, int id) { 
                dialog.cancel(); 
            }
        });
        adb.show();         
    } catch (ActivityNotFoundException activityException) {
        Throwable e = null;
        Log.e("helloandroid dialing example", "Callfailed", e); 
    }
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
MissCoder87
  • 2,669
  • 10
  • 47
  • 82

1 Answers1

4

I think you need to use an activity to show something over top of the in call screen. A dialog will not work since you are showing it from this activity that you've posted, but this activity won't be on top of the stack any more once you start the call intent.

See the answer here: Android - How to display a dialog over a native screen?

for how you can style your (new) activity to look like a dialog though, which will give you the same visual effect you are after.

Once you create a new activity using the parameters shown in that question then you can start it with startActivity after you start the callIntent

public void makecall(View view){ 
    try {
        Intent callIntent = new Intent(Intent.ACTION_CALL);
        callIntent.setData(Uri.parse("tel:NUMBER"));
        startActivity(callIntent);
        Toast.makeText(this, "TEST",Toast.LENGTH_LONG).show(); 

        Runnable showDialogRun = new Runnable() {
            public void run(){
                Intent showDialogIntent = new Intent(this, DialogActivity.class);
                startActivity(showDialogIntent);
            }
        };
        Handler h = new Handler();
        h.postDelayed(showDialogRun, 2000);
    } catch (ActivityNotFoundException activityException) {
        Throwable e = null;
        Log.e("helloandroid dialing example", "Callfailed", e); 
    }
}

Delaying the dialog startActivity by a second or two seems to make it more likely to actually splash on top of the phone screen.

Community
  • 1
  • 1
FoamyGuy
  • 46,603
  • 18
  • 125
  • 156
  • Hi, Thanks for that. I've tried the suggestion on the other location and done the above code, however it still loads the dialog behind the call screen, then when i end the call shows me the dialog – MissCoder87 Apr 08 '13 at 13:42
  • That's what my activity looks like – MissCoder87 Apr 08 '13 at 13:45
  • You're welcome, glad you got it working. I updated the code in my answer for anyone who comes by this in the future. – FoamyGuy Apr 08 '13 at 13:59
  • With this method, Can i not control elements on the page? When I try and add a label on the popup dialog it falls over straight away – MissCoder87 Apr 08 '13 at 14:54
  • ou should be able to control them, post a new question showing the layout / activity code you are using, and what it is that you are trying to do with it. – FoamyGuy Apr 08 '13 at 15:03