Handle App Availability
This guide walks you through checking if the Get Mini application is installed on the user’s device. You’ll learn how to catch the exception when the app is missing and redirect users to the Google Play Store.
Requirements
Before following the steps, ensure you have:
- Android application with Intent launching capability
- Google Play Store access on the device
Always implement this check before attempting to launch payment Intents to provide a better user experience.
App Availability Check
This section guides you through implementing exception handling to detect when the Get Mini app is not installed and guide users to install it.
Step 1: Wrap Intent Launch in Try-Catch
When you attempt to launch an Intent for the Get Mini app, the Android system will throw an ActivityNotFoundException if the app is not installed. Wrap your Intent launch call in a try-catch block to handle this scenario gracefully.
The following code demonstrates how to catch the exception:
String playStoreUrl = "https://play.google.com/store/apps/details?id=es.android.redsys.Get Mini.movil";
try {
// Attempt to launch the Get Mini intent
paymentLauncher.launch(intent);
} catch (ActivityNotFoundException e) {
// Get Mini app is not installed
showInstallDialog(playStoreUrl);
}This approach works with both startActivityForResult and the modern ActivityResultLauncher API.
Step 2: Show Installation Dialog
When the Get Mini app is not found, display a dialog that explains the situation and provides an option to install the app from the Google Play Store.
private void showInstallDialog(String playStoreUrl) {
new AlertDialog.Builder(this)
.setTitle("Get Mini Not Found")
.setMessage("The Get Mini app must be installed to process payments.")
.setPositiveButton("Install", (dialog, which) -> {
// Open Play Store
Intent storeIntent = new Intent(Intent.ACTION_VIEW);
storeIntent.setData(Uri.parse(playStoreUrl));
startActivity(storeIntent);
})
.setNegativeButton("Cancel", null)
.show();
}Step 3: Handle Return from Play Store (Optional)
After the user returns from the Play Store, you may want to check if they installed the app and retry the transaction. You can implement this by checking app availability when your Activity resumes.
@Override
protected void onResume() {
super.onResume();
// Check if user returned from Play Store and installed the app
if (shouldRetryTransaction && isMposAppInstalled()) {
retryTransaction();
}
}
private boolean isMposAppInstalled() {
Intent intent = new Intent("es.redsys.paysys.mPOSRedsys_PAYMENT_REQUEST");
return getPackageManager().resolveActivity(intent, 0) != null;
}Next Steps
Now that you know how to handle app availability, you can:
- Review Prerequisites and Setup for environment requirements
- Learn about Process a Payment to implement payment transactions
- Read Handle Transaction Results to process Get Mini responses