【问题标题】:Pushing phone call screen in to background whilst making a call拨打电话时将电话屏幕推到后台
【发布时间】:2013-04-08 13:16:47
【问题描述】:

我们正在使用 android 应用程序进行一些评估,当评估员到达现场时,他们需要在通话时登录办公室。有一个参考号码,我真的很想在电话响铃后保留在电话显示屏上。

最好是在拨号器屏幕顶部显示一个显示号码的对话框。

我尝试过这样做,但它只是超越了对话框并显示了调用屏幕。无论如何将拨号器推到后台并继续向用户显示对话框?

这是我目前所拥有的:

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); 
    }
}

【问题讨论】:

  • 抱歉 - 有人在编辑中为我修复了格式。

标签: android overriding phone-call


【解决方案1】:

我认为您需要使用活动来在通话屏幕顶部显示某些内容。对话框将不起作用,因为您正在从您发布的此活动中显示它,但一旦您启动调用意图,此活动将不再位于堆栈顶部。

在此处查看答案:Android - How to display a dialog over a native screen?

了解如何将(新)活动设置为看起来像一个对话框,这将为您提供与您所追求的相同的视觉效果。

使用该问题中显示的参数创建新活动后,您可以在启动 callIntent 后使用 startActivity 启动它

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); 
    }
}

将对话框 startActivity 延迟一两秒似乎使它更有可能真正飞溅到手机屏幕上。

【讨论】:

  • 嗨,谢谢。我已经在其他位置尝试过这个建议并完成了上面的代码,但是它仍然会在通话屏幕后面加载对话框,然后当我结束通话时会显示对话框
  • 这就是我的活动的样子
  • 不客气,很高兴你能成功。我为将来遇到此问题的任何人更新了答案中的代码。
  • 用这个方法,我可以不控制页面上的元素吗?当我尝试在弹出对话框上添加标签时,它会立即掉下来
  • 你应该能够控制它们,发布一个新问题,显示你正在使用的布局/活动代码,以及你试图用它做什么。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多