API LEVEL 34 java.lang.SecurityException: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED

I’m currently having the same problem. I am in the middle of testing it, but I believe this will work:

In Engine\Build\Android\Java\src\com\epicgames\ue4\GameActivity.java.template (this .template file is used to construct the actual GameActivity.java file that gets packaged)

you can see the call to registerReceiver that is causing the problem in onStart()

registerReceiver(consoleCmdReceiver, new IntentFilter(Intent.ACTION_RUN));

You’ll also see that it is only added in non-shipping builds for receiving console commands, so I think RECEIVER_EXPORTED is the correct option to use here, it just needs adding as a third parameter to the registerReceiver call.

I’ve wrapped it in a targetSdkVersion check to be on the safe side, but it isn’t strictly neccessary. Just replace the current call to registerReceiver with this:

            try 
			{
				PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
				targetSdkVersion = packageInfo.applicationInfo.targetSdkVersion;
			}
			catch (PackageManager.NameNotFoundException e) 
			{
				Log.debug(e.getMessage());
			}
			if ( targetSdkVersion >= 34 )
			{
				registerReceiver(consoleCmdReceiver, new IntentFilter(Intent.ACTION_RUN), RECEIVER_EXPORTED);
			}
			else
			{
				registerReceiver(consoleCmdReceiver, new IntentFilter(Intent.ACTION_RUN));
			}

Cheers,
Matt

8 Likes