javaandroidaudioandroid-intentmedia

Getting all android packages that can handle Intent.ACTION_MEDIA_BUTTON Android 13 API33


In previous versions of Android the following code used to work for getting all packages installed that could handle the Intent.ACTION_MEDIA_BUTTON However, now it does not work as it used to. Does anyone have insight as to why this doesn't work anymore? as well as a new method (Android 13 API 33) for getting the packages that can handle Intent.ACTION_MEDIA_BUTTON?

//get all media players
Intent sendIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
mediaPlayers = this.getPackageManager().queryBroadcastReceivers(sendIntent, 0);

Solution

  • To comply with package visibility rules on Android 11 and higher, you will need a <queries> element as a child of the root <manifest> element, something like:

    <queries>
        <intent>
            <action android:name="android.intent.action.MEDIA_BUTTON" />
        </intent>
    </queries>