首页 > 解决方案 > 在没有窗口类型的服务中显示 AlertDialog

问题描述

我会尝试解释我感兴趣的内容,如果你能帮助我,我会很高兴。您是否知道在不设置类型 TYPE_SYSTEM_ALERT / TYPE_APPLICATION_OVERLAY 的情况下在活动之外(服务中)显示 AlertDialog 的方法?例如以某种方式全局预设它,也许使用 ContextWrapper (我不知道它是否可以完成),然后以标准方式创建 AlertDialog?这似乎是一个奇怪的问题,但我需要它,因为我无法为某些外部警报对话框设置类型,最后我的目标是让这段代码在服务中工作

AlertDialog.Builder builder = new AlertDialog.Builder(context)
.setTitle("Example")
.setMessage("Example")
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialogInterface, int i) {
        dialogInterface.dismiss();
    }
});
AlertDialog alertDialog = builder.create();
alertDialog.show();

标签: android-alertdialogtype-application-overlay

解决方案


推荐阅读