NotificationService system_server W 由于发布 toast 时包不在前台,因此阻止 com.example.androidtest 包中的自定义 toast 块引用
当我尝试在请求许可后立即显示自定义 Toast 时 在 Android >= 11 上,我收到上述警告,并且自定义 Toast 不会显示
private val requestPermissionLauncher = registerForActivityResult(
ActivityResultContracts.RequestPermission()
) { isGranted: Boolean ->
}
override fun onCreate(savedInstanceState: Bundle?) {
...
buttonCamera.setOnClickListener {
requestPermissionLauncher.launch(android.Manifest.permission.CAMERA)
makeCommonToast("ABc").show()
}
}
private fun makeCustomToast(message: CharSequence): Toast {
return Toast.makeText(context, "", Toast.LENGTH_LONG).apply {
val rootView = LayoutInflater.from(context).inflate(R.layout.my_custom_toast, null)
view = rootView
val textView = rootView.findViewById<TextView>(R.id.text_message)
textView.text = message
}
}
我以为应用程序仍在前台,但 Toast 不会显示