Android Inter-App Communication

Pre-Communication Checks

Before a partner app attempts to communicate with an installation of the Authenticator App, it should determine if the app has been installed on the device. The getPackageInfo methods of the PackageManager class can be used to do this.

Initiation

The partner should use the startActivityForResult method of the Activity class to initiate communication with the Authenticator App installation.

Result Handling

The onActivityResult method in the partner app activity is called when the Authenticator App installation exits.

If the Authenticator App installation crashed or was unable to complete the requested action, the resultCode argument value will be Activity.RESULT_CANCELED. The partner should show an error view to the user.

If the Authenticator App installation was able to complete the requested action, the resultCode argument value will be Activity.RESULT_OK and the requestCode argument value will match the value given in the call to the startActivityForResult method. The partner app should continue the current activity.

Example

The following example shows how communication with an Authenticator App installation could be initiated from a partner app activity.

Intent intent = new Intent();

// Identify the Authenticator App package name and component.
intent.setClassName(
  "<authenticator-package-name>",
  "<authenticator-activity-class-name>"
);

// Indicate the active session.
intent.putExtra("ID", "<session-id>");

startActivityForResult(intent, requestCode);