Hirdetés

Új hozzászólás Aktív témák

  • thiclyoon

    aktív tag

    válasz Ablakos #4972 üzenetére

    A kód jó :) valószínűleg a gond az android api miatt van: "If your app targets Android 8.0 or higher, you cannot use the manifest to declare a receiver for most implicit broadcasts (broadcasts that don't target your app specifically)" [link]

    Ha a kódot így szeretnéd ellenőrizni, akkor a module szintű build.gradle targetSdkVersion-jét vedd kisebbre (pl. 22), és egy ugyanilyen api-val rendelkező emulátoron teszeld. Viszont éles projekt, stb. esetén tedd is vissza a target-et, és próbáld meg kódból (manifest-ből töröld a kódodat):
    val intentFilter = IntentFilter("android.intent.action.AIRPLANE_MODE")
    val receiver: BroadcastReceiver = object : BroadcastReceiver() {
    override fun onReceive(context: Context?, intent: Intent?) {
    Toast.makeText(this@MainActivity, "changed", Toast.LENGTH_SHORT).show()
    }
    }
    this.registerReceiver(receiver, intentFilter)

Új hozzászólás Aktív témák