Sobes.tech
Middle

What does the attribute android:exported with values 'true' and 'false' mean?

sobes.tech AI

Answer from AI

The android:exported attribute in the Android App manifest (AndroidManifest.xml) determines whether your app's components (Activity, Service, BroadcastReceiver, ContentProvider) can be accessed by other applications or processes in the system.

android:exported="true":

  • The component can be invoked or accessed from other applications.
  • For example, if an Activity is marked as exported="true", another application can start this Activity using an Intent.
  • This is necessary if your component needs to interact with other applications (e.g., providing data via ContentProvider, starting a service from outside).
  • When using Intent Filters with certain categories (e.g., android.intent.category.LAUNCHER), the component is by default exported="true", even if the attribute is not explicitly set or is set to false.

android:exported="false":

  • The component is only available within its own application or processes with the same user ID.
  • Other applications cannot directly access this component.
  • This setting is the default for most components on Android 12 (API level 31) and above if the component does not have intent filters.
  • Using exported="false" is a good security practice as it limits potential entry points for third-party applications.
<activity android:name=".MainActivity"
          android:exported="true"> // This activity is accessible from other applications
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

<activity android:name=".InternalActivity"
          android:exported="false"> // This activity is only available within our application
</activity>

<service android:name=".DataService"
         android:exported="true"> // The service can be started externally
    <intent-filter>
        <action android:name="com.example.myapp.START_DATA_SERVICE" />
    </intent-filter>
</service>

<provider android:name=".MyContentProvider"
          android:authorities="com.example.myapp.provider"
          android:exported="false" // The provider is only accessible within the app
          android:grantUriPermissions="true"/>
What does the attribute android:exported with values… - sobes.tech