How to Restrict the Recipient of an Android Intent Carrying Sensitive Data
When passing data through an Intent, it is important to determine which application may receive it. An implicit Intent without a fully qualified component class name or a recipient package creates an interception risk: another application can register a matching intent filter. If the transfer contains personal data or a session token, the consequences affect user privacy. We will define a recipient selection rule for one outgoing transfer and test it in an entirely fictional environment using apps we own and synthetic data.
Where the Trust Boundary Lies
The developer’s task is to bind a specific transfer to the intended application. The trust boundary lies between the sender and the external recipient: an application having a matching intent filter does not mean the product intended to send data to it. Android documentation associates the risk of implicit Intent interception with the absence of a fully qualified component class name or a recipient package.
Start by defining the product rule: only the application with the specified package may receive this transfer. This article covers only recipient selection for an ordinary outgoing Intent. Other mechanisms for communication between applications require separate decisions. Explicit addressing alone also does not prove the authenticity of the installed application.
A Fictional Example and an Addressing Rule
Imagine an entirely fictional test environment: an app we own called “Practice Budget” sends a record to another app we own called “Practice Archive.” A third app we own, “Control,” has a matching intent filter and helps verify the delivery boundary. Every run uses only a synthetic marker, such as demo-transfer-041, instead of real financial information. This is a test identifier, not personal data or a valid token.
For the normal transfer, we will define this rule: the sender calls setPackage() with the package of “Practice Archive.” This is the method Android documentation recommends for restricting the recipient. Inspect the final Intent immediately before startActivity(): the package restriction must remain in place after the transfer has been prepared, and the test payload must contain only the synthetic marker.
Verifying Delivery with a Positive Control
The following are editorially proposed acceptance tests, not an official Android procedure. Install both recipient apps you own. First, use separate direct test launches to confirm that both “Practice Archive” and “Control” record receipt of their respective synthetic markers. This is a positive control: without it, an empty control app log could indicate that the test is not working.
Next, perform the normal transfer from “Practice Budget” using setPackage() and a new, unique marker. Correlate the sender’s record and both recipients’ observations with this specific run. Acceptance requires three observations: the correct package remains set before launch, “Practice Archive” records the new marker, and “Control” does not receive it. Executing the send call alone does not confirm delivery to the intended application.
When the Intended Recipient Is Absent
Define the product’s behavior separately for cases where “Practice Archive” is absent: display a clear message that the transfer cannot be completed, and do not send the marker to another application. This is a proposed failure-handling rule, not a promise of automatic platform behavior. The Android guide’s example of launching without an app selection step assumes that an application capable of handling the Intent is available.
To test this, uninstall the intended recipient while leaving your “Control” app with its matching filter installed, then repeat the transfer with a new marker. Verify the failure message and confirm that the control app does not receive the marker. Also inspect the failure path: it must not remove the package restriction or retry the transfer through an implicit Intent or chooser with the same marker. Otherwise, the fallback would violate the original product rule.
What to Fix First
First, fix the addressing of the selected sensitive transfer and its failure path. Then run the positive control and the main delivery test. This sequence connects a specific fix to an observable result: the restriction is present before launch, the intended application receives the marker, the control app does not, and the absence of the recipient does not cause delivery to another application.
If the product genuinely needs an implicit Intent, the documentation recommends excluding sensitive information and mutable objects that must not be disclosed. For an implicit Intent capable of launching at least two applications, it recommends explicitly presenting the user with an app chooser. However, that choice does not satisfy the rule adopted here of a single intended recipient: it cannot serve as a fallback for the sensitive transfer under discussion.
How to Interpret the Test Results
Successful tests confirm compliance with the rule only for the scenario examined in your own test environment. The absence of the marker in the control app is meaningful alongside a working positive control and confirmed receipt by the intended recipient. These observations do not prove the absence of all leaks and do not replace verification of the installed application’s authenticity.
Document the addressing rule and acceptance criteria alongside the transfer description so that you can repeat the tests when it changes. If your product has a website or a web component, you can start with a free website or web-product audit from CheckMyApp. The Android test environment described here remains a separate check of recipient selection for an outgoing Intent.