How to Launch (Direct) another app from your flutter app
In one of my recent projects, I was tasked with implementing functionality to launch an external app from within our Flutter application. The requirements were simple:
After doing some research, I came across the external_app_launcher package, which provided an easy and effective solution to meet these requirements. In this article, I’ll walk you through how I achieved this functionality step-by-step.
Step 1: Adding the Package
To get started, add the external_app_launcher package to your project by running the following command:
flutter pub add external_app_launcher
Once added, run flutter pub get to install the package.
Step 2: Setting Up Native Configurations
To ensure compatibility with native platforms, we need to update the configuration files for both Android and iOS.
Android Configuration
<queries>
<package android:name="com.example.targetapp" /> <!-- Replace with the package name of your target app -->
</queries>
<category android:name="android.intent.category.HOME"/>
<category android:name="android.intent.category.DEFAULT"/>
iOS Configuration
<key>LSApplicationQueriesSchemes</key>
<array>
<string>exampleapp</string> <!-- Replace with the URL scheme of the target app -->
</array>
Step 3: Implementing the Functionality
Once the native configurations are set up, you can implement the external app launcher in Flutter.
Here’s an example of how to use the external_app_launcher package:
import 'package:external_app_launcher/external_app_launcher.dart';
void launchExternalApp() async {
try {
await LaunchApp.openApp(
androidPackageName: 'com.example.targetapp', // Replace with the target app's package name
iosUrlScheme: 'exampleapp://', // Replace with the iOS app's URL scheme
appStoreLink: 'https://apps.apple.com/us/app/exampleapp/id123456789', // Replace with the App Store link
openStore: true, // Redirect to the store if the app is not installed
);
} catch (e) {
print('Failed to launch app: $e');
}
}
Step 4: Testing
To test the functionality:
Challenges Faced
While working on this feature, I initially encountered issues with Play Store redirection on Android. After some troubleshooting, I found that the problem was resolved by adding the <queries> tag in the AndroidManifest.xml file.
Conclusion
The external_app_launcher package is a fantastic tool for implementing external app launching functionality in Flutter. It’s simple, flexible, and handles both scenarios (app installed and not installed) seamlessly.
If you have a similar requirement, I highly recommend using this package. Just don’t forget to configure y
our AndroidManifest.xml and Info.plist files properly to avoid compatibility issues.
Need help with your app? Whether you want to fix bugs, implement new features, or bring a fresh idea to life, I’m here to help! Feel free to reach out, and let’s turn your app into something amazing. 😊
Flutter Developer | Crafting User-Centric Mobile Solutions | Expert in Wellness, Healthcare & Construction Apps with Scalable Architectures
3moMuhammad, thanks for sharing!
Sr. Product Engineer at Gibsons technologies india pvt. ltd
6moFor android it will work , for ios preferable way is only via universal or deep linking
Sr. Product Engineer at Gibsons technologies india pvt. ltd
6mothis is not working now for higher ios version > 17 mostly