XML
XML
2. **Handling Actions**:
- An intent filter can specify one or more actions (such as `VIEW`, `EDIT`,
`MAIN`, etc.). Actions define what the intent is trying to accomplish. For
instance, an activity with an intent filter designed to handle the `ACTION_VIEW`
action can be started to view data.
4. **Categories**:
- Categories provide additional information about how the intent should be
handled. For example, the `CATEGORY_LAUNCHER` category indicates that the activity
is an entry point of the application and should appear in the device's app
launcher.
- **Receiving SMS**:
```xml
<receiver android:name=".SmsReceiver">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
```
This intent filter configures `SmsReceiver` to listen for intents that indicate
an SMS message has been received.
- **Main Activity Declaration**:
```xml
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
```
This intent filter makes `MainActivity` the entry point of the app, meaning it
will appear in the launcher as the app icon that users can click to start the app.
- **Flexibility**: They allow components to handle a wide range of actions and data
types without hard coding specific component names, making the app more modular and
adaptable.
- **Integration**: Intent filters enable an app to seamlessly integrate with other
apps and the Android OS itself, responding to intents broadcasted by other apps or
the system.
- **User Experience**: By specifying intent filters, developers can ensure that
their app responds appropriately to user actions or external notifications, thereby
enhancing the user experience.
Intent filters are a powerful feature of the Android platform, enabling developers
to build apps that can interact effectively with the system and other apps.