Setting Exported on Activities, Broadcasts, and Services

Yusuf I.

The Problem

Since Android 12, a requirement for using Activities, Broadcast Receivers, or Services with Intent Filters is to set an exported attribute in the Android Manifest.

Uploading an APK to the Play Store without setting an exported attribute might result in an error such as:

You uploaded an APK or Android App Bundle which has an activity, activity alias, service, or broadcast receiver with intent filter, but without the 'android: exported' property set. This file can't be installed on Android 12 or higher.

The Solution

We’ll go through examples of setting the exported attribute for Activities, Broadcast Receivers, and Services.

Setting the exported property to true allows external apps to launch the component while setting it to false allows only your app to launch the component.

Below is an example of an activity element with the intent-filter and the exported attributes set:

<activity android:name=".MainActivity" android:exported="true" android:theme="@style/Theme.App.Starting"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter>

Activities that implement android.intent.category.LAUNCHER in an intent-filter should set exported to true.

Next, we have an example of a Broadcast Receiver:

<receiver android:name=".ExampleBroadcastReceiver" android:exported="false"> <intent-filter> <action android:name="EXAMPLE_BROADCAST" /> </intent-filter> </receiver>

If the receiver should listen for broadcasts from the system or external apps then set exported to true.

Finally, we have an example of a Service:

<service android:name=".MessagingService" android:exported="false"> <intent-filter> <action android:name="" /> </intent-filter> </service>

As you can see, all three examples implement Intent Filters. You don’t have to set the exported attribute if you are not using an Intent Filter.

Loved by over 4 million developers and more than 90,000 organizations worldwide, Sentry provides code-level observability to many of the world’s best-known companies like Disney, Peloton, Cloudflare, Eventbrite, Slack, Supercell, and Rockstar Games. Each month we process billions of exceptions from the most popular products on the internet.

Share on Twitter
Bookmark this page
Ask a questionJoin the discussion

Related Answers

A better experience for your users. An easier life for your developers.

© 2024 • Sentry is a registered Trademark
of Functional Software, Inc.