我已经创建了head气泡,该气泡在28之前的旧API上都可以完美运行。在最新的API 29上,我无法从后台在Tap应用上打开。
这里是头部气泡截图
Screenshot of head bubble when an app is in background
这是我当前的代码...
override fun onCreate() {
super.onCreate()
mCallHeadView =
LayoutInflater.from(this).inflate(R.layout.call_head, null);
var params: WindowManager.LayoutParams = WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
LayoutParams.TYPE_APPLICATION_OVERLAY,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT
)
//val params = LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT, LayoutParams.TYPE_PHONE,
LayoutParams.FLAG_NOT_FOCUSABLE, PixelFormat.TRANSLUCENT)
params.gravity = Gravity.TOP or Gravity.END
params.x = 0
params.y = 270
mWindowManager = getSystemService(WINDOW_SERVICE) as? WindowManager;
if( mWindowManager != null){
mWindowManager!!.addView(mCallHeadView, params);
}
var closeButton = mCallHeadView!!.findViewById<ConstraintLayout> .
(R.id.callHead)
closeButton.setOnClickListener {
val i = Intent()
i.setClass(this,MainActivity::class.java)
i.flags = Intent.FLAG_ACTIVITY_NEW_TASK
startActivity(i)
stopSelf()
}
由于在新版本的Android(28或更高版本)中实现Bubbles有所不同因此,请尝试关注Android Documentation或任何新教程,例如this