需要使用到悬浮窗权限
val builder: AlertDialog.Builder = AlertDialog.Builder(this)
builder.setMessage("from MyService")
val dialog: AlertDialog = builder.create();
//创建全局对话框需要在show之前调用
dialog.window.setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT)
dialog.show()
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />