AVC: отказано {прочитать} фрагмент Android - PullRequest
0 голосов
/ 12 ноября 2018

У меня есть модальное диалоговое окно , которое я создал с помощью 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 аудит (0.0: 6789172): avc: отклонено {read} для name = "perf_ioctl" dev = "proc" ino = 4026533700 scontext = u: r: untrusted_app: s0: c512, c768 tcontext = u: object_r: proc: s0 tclass = file permissive = 0

Это странно, потому что я делаю то же самое в другом фрагменте (Accueil.kt), но у меня нетпроблема вообще.

РЕДАКТИРОВАТЬ: Очевидно, это связано с диалогом, если я вызываю фрагмент без диалога, у меня есть мои данные.Так что я должен изменить?

1 Ответ

0 голосов
/ 12 ноября 2018

Вы должны вызвать 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()
}
...