Skip to content Skip to sidebar Skip to footer

Broadcast Receiver Not Working In Android Studio 4.0.0

I am new to Android Studio and the broadcast receiver is not working. 'Broadcast Received!!!' doesn't appear on the screen. Android Studio version: 4.0 Android Version in the emula

Solution 1:

Implicit broadcasts like this one have been blocked on Android since Android 8.0, nearly three years ago.

Solution 2:

Implicit broadcasts are blocked to prevent unwanted apps from matching your intent and starting (that's why they will only work with receivers registered at runtime).

Since you're sending broadcast to specific receiver you can modify your intent to be explicit by declaring target package:

publicvoidsendBroadcast(View view) {
    Intent intent = new Intent();
    intent.setAction("com.example.sendbroadcast");
    // add this line to have intent delivered explicitly to your app// use package name of your ReceiveBroadcast project
    intent.setPackage("com.example.recievebroadcast");
    intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
    sendBroadcast(intent);
    System.out.println("Sent!!!");
}

Post a Comment for "Broadcast Receiver Not Working In Android Studio 4.0.0"