Search code examples
androidbroadcastreceivercommunication

Broadcast Receiver for Android 9


I have a custom Broadcast Receiver structure to communicate 2 different application. I know its deprecated for Android 9. Are there any way to use my custom Broadcast Receiver on that device.


Solution

  • "As part of the Android 8.0 (API level 26) Background Execution Limits, apps that target the API level 26 or higher can no longer register broadcast receivers for implicit broadcasts in their manifest."

    I only changed my application targetSdkVersion 31 to 25 from gradle file. That worked for me.


    Old gradle config


    defaultConfig {
            minSdkVersion 21
            targetSdkVersion 31
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
            consumerProguardFiles "consumer-rules.pro"
        }
    

    New gradle config


    defaultConfig {
            minSdkVersion 21
            targetSdkVersion 25
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
            consumerProguardFiles "consumer-rules.pro"
        }