android - avc: 拒绝 { 读取 } 片段 Android
问题描述
我有一个用 XML 创建的模式对话框。然后,我在kotlin中展示它(它不是一个真正的对话框视图,而不仅仅是一个信息弹出窗口)。
请参阅 XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".AlertsDialogRemi"
android:id="@+id/alertLayoutRoot"
android:orientation="vertical"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:ignore="UselessParent"
>
<RelativeLayout
android:id="@+id/layoutTopAlert"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="33dp"
android:gravity="center"
>
<LinearLayout
android:id="@+id/layoutAlert"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@color/orange"
>
<TextView
android:id="@+id/alerte_title"
style="@style/titleActu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="66dp"
android:text="@string/alertes"
android:textColor="@color/colorWhite" />
<ViewFlipper
android:id="@+id/viewFlipperAlert"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/orange">
</ViewFlipper>
<LinearLayout
android:id="@+id/dotNavAlert"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="horizontal">
</LinearLayout>
</LinearLayout>
<Button
android:id="@+id/close_modal_alerte"
style="@style/Base.Widget.AppCompat.Button.Borderless"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="@android:color/transparent"
android:text="Fermer"
android:layout_below="@id/layoutAlert"/>
</RelativeLayout>
<ImageView
android:id="@+id/alert_logo"
android:layout_width="66dp"
android:layout_height="66dp"
android:layout_centerHorizontal="true"
android:src="@drawable/alertes" />
</RelativeLayout>
</LinearLayout>
此函数显示 MainActivity.kt 中的模式(我正在使用片段和导航抽屉):
lateinit var mydialog : Dialog
lateinit var txt : TextView
override fun onOptionsItemSelected(item: MenuItem): Boolean {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
var fragment: Fragment? = null
when (item.itemId) {
R.id.action_alert -> {
showDialog()
return true
}
else -> return super.onOptionsItemSelected(item)
}
}
fun showDialog(){
mydialog = Dialog(this, R.style.DialogCustomTheme)
mydialog.requestWindowFeature(Window.FEATURE_NO_TITLE)
mydialog.setContentView(R.layout.alerts_dialog_remi)
txt = mydialog.findViewById(R.id.close_modal_alerte)
txt.isEnabled = true
txt.setOnClickListener{
mydialog.cancel()
}
mydialog.show()
}
在 AlertsDialogRemi.xml 中,我有这个:
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val alerts = arrayOf("AlertsDialogRemi 1", "AlertsDialogRemi 2", "AlertsDialogRemi 3")
for(alert in alerts){
Log.i(TAG, "Alert : $alert")
}
当我尝试访问 AlertDialogRemi.kt 中的警报变量时,我的日志中出现此错误:
W/RenderThread: type=1400 audit(0.0:6789172): avc: denied { read } for name="perf_ioctl" dev="proc" ino=4026533700 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u :object_r:proc:s0 tclass=文件许可=0
这很奇怪,因为我在另一个片段(Accueil.kt)中做了同样的事情,但我一点问题都没有。
编辑:显然,这是由于对话框,如果我在没有对话框的情况下调用片段,我有我的数据。那么我应该改变什么?
解决方案
您应该mydialog.create()
在调用mydialog.show()
方法或尝试访问其内部视图之前调用。
fun showDialog(){
mydialog = Dialog(this, R.style.DialogCustomTheme)
mydialog.requestWindowFeature(Window.FEATURE_NO_TITLE)
mydialog.setContentView(R.layout.alerts_dialog_remi)
mydialog.create()
txt = mydialog.findViewById(R.id.close_modal_alerte)
txt.isEnabled = true
txt.setOnClickListener{
mydialog.cancel()
}
mydialog.show()
}
推荐阅读
- javascript - 如何在删除项目之前添加确认按钮?
- java - 带有点和散列的矩阵中的模式
- listview - Xamarin Forms ListView 项目自定义外观
- search - Solr 嵌套文档 - 不同子类型的方面字段
- ruby-on-rails - 为什么 class_eval 以不同的方式评估字符串和块?
- amazon-web-services - Sanbox 环境的 IAM 政策
- sql - 选项框表仅搜索 SQL (MS-Access) 上的数字
- javascript - 在容器中以相等的距离放置绝对位置元素
- r - 使用 vroom 在 R 中读取日期列和所有其他列作为双精度
- amazon-eks - AWS EKS 自定义 AMI 托管节点组引导文件不存在