skip to Main Content

open app from flutter web app in mobile if already installed then simply open the app. from web app i can’t open my app that is already installed.
in code when i run in android then my app will open but when i run in chrome then other myapp will not opened


  void openMyApp() async {
     final myAppUrl = "myapp://open"; // Custom URL scheme for your app
    final playStoreUrl =  "https://play.google.com/store/apps/details?id=com.mxtech.videoplayer.ad"; 
        
    // Try to open the app
    if (await canLaunchUrl(Uri.parse(myAppUrl))) {
      print("launch app");
      await launchUrl(Uri.parse(myAppUrl));
    } else {
      // If the app is not installed, open the Play Store link after a delay
      await Future.delayed(const Duration(milliseconds: 1500), () async {
        if (await canLaunch(playStoreUrl)) {
          await launch(playStoreUrl);
        }
      });
    }
  }
}

2

Answers


  1. Is the other app you’re launching made by you? If so, you can tell Android to launch it when a certain URL is encountered, using app links:

    https://developer.android.com/training/app-links#android-app-links

    You can add an HTTP(S) URL to your manifest file. When the user has your app installed opening the URL will open the app, and if your app is not installed, they are redirected to the HTTP(S) site in their browser (which may redirect them to the Play Store or some other place.

    If not, maybe try to clarify the text in your question a little bit. It’s a bit confusing to read.

    Login or Signup to reply.
  2. For open your mobile app from a Flutter web app using a custom URL scheme

    AndroidManifest.xml

    <activity>
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="myapp" android:host="open" />
        </intent-filter>
    </activity>
    

    Info.plist

    <key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleURLName</key>
            <string>com.yourcompany.app</string>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>myapp</string>
            </array>
        </dict>
    </array>
    

    Flutter code

    void openMyApp() async {
      final myAppUrl = "myapp://open"; // Custom URL scheme for your app
      final playStoreUrl = "https://play.google.com/store/apps/details?id=com.mxtech.videoplayer.ad";
    
      try {
        // Attempt to open the app
        if (await launchUrl(Uri.parse(myAppUrl), mode: LaunchMode.externalApplication)) {
          print("App launched successfully");
        } else {
          // If the app is not installed, fallback to the Play Store
          await Future.delayed(const Duration(milliseconds: 1500), () async {
            if (await canLaunch(playStoreUrl)) {
              await launch(playStoreUrl);
            }
          });
        }
      } catch (e) {
        print("Error launching the app: $e");
        // Open the Play Store if the app can't be opened
        await launch(playStoreUrl);
      }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search