Sentry Answers>Android>

Setting Exported on Activities, Broadcasts, and Services

Setting Exported on Activities, Broadcasts, and Services

Yusuf I.

The ProblemJump To Solution

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:

Click to Copy
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:

Click to Copy
<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:

Click to Copy
<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:

Click to Copy
<service android:name=".MessagingService" android:exported="false"> <intent-filter> <action android:name="com.google.firebase.MESSAGING_EVENT" /> </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.

  • Sentry BlogAndroid Manifest Placeholders
  • Sentry BlogHow to handle Android exceptions and avoid application crashes
  • ResourcesSentry vs. Crashlytics: The Mobile Developer's Decision-Making Guide
  • Syntax.fm logo
    Listen to the Syntax Podcast

    Tasty treats for web developers brought to you by Sentry. Get tips and tricks from Wes Bos and Scott Tolinski.

    SEE EPISODES

Loved by over 4 million developers and more than 100,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.

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