我们正在使用 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);
}
}
最佳答案
我认为您需要使用一个 Activity 在通话屏幕顶部显示一些内容。对话框将不起作用,因为您是从您发布的此 Activity 中显示它的,但一旦您启动调用 Intent ,此 Activity 将不再位于堆栈顶部。
在这里查看答案:Android - How to display a dialog over a native screen?
了解如何将您的(新) Activity 设置为看起来像对话框,这将为您提供与您想要的相同的视觉效果。
使用该问题中显示的参数创建新 Activity 后,您可以在启动 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 延迟一两秒似乎使它更有可能真正溅到手机屏幕顶部。
关于android - 调用电话时将电话屏幕插入后台,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15880091/