0

I have been trying to implement AppLink in my Flutter application for android which is currently in development/debug mode, but the AppLink doesn't work. When I hit the URL through browser in my mobile which is running the Flutter application in debug/development mode, the app doesn't opens. I suppose there is some problem inside the Flutter app implementation.

Steps I have tried

  1. Created the assetlinks.json file and added the following details:

      [
        {
          "relation": [
            "delegate_permission/common.handle_all_urls"
          ],
          "target": {
            "namespace": "android_app",
            "package_name": "com.foxjek.fox_jek_user",
            "sha256_cert_fingerprints": [
             "73:EA:74:0C:B4:6B:99:37:C0:CF:B9:BD:54:EB:2C:51:04:5A:3A:6A:0E:64:0B:27:B8:73:B2:51:4B:B3:CE:F9"
            ]
          }
        }
      ]
    
  2. And uploaded it on the server on the root directory under the folder .well-known and tested through the Google Digital Asset Links and the Test is success.

  3. Now I have installed the uni_link 0.5.1 library for AppLinking implementation by following the steps defined here

  4. After that I have followed the following steps to setup everything:

    • Here is my AndroidManifest.xml file under the android/app/src/main directory. Inside the <activity> tag (usually named MainActivity), I have added the <intent-filter> element:

         <manifest xmlns:android="http://schemas.android.com/apk/res/android"
             package="com.foxjek.fox_jek_user">
      
             <uses-permission android:name="android.permission.INTERNET" />
             <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
             <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
             <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
             <uses-permission android:name="android.permission.READ_CONTACTS" />
      
             <uses-feature android:name="android.hardware.location.gps" />
             <uses-feature
                 android:glEsVersion="0x00020000"
                 android:required="true" />
      
             <!-- Provide required visibility configuration for API level 30 and above -->
             <queries>
      
                 <intent>
                     <action android:name="android.intent.action.VIEW" />
                     <data android:scheme="sms" />
                 </intent>
                 <!-- If your app makes calls -->
                 <intent>
                     <action android:name="android.intent.action.DIAL" />
                     <data android:scheme="tel" />
                 </intent>
      
      
                 <!-- If your app emails -->
                 <intent>
                     <action android:name="android.intent.action.SEND" />
                     <data android:mimeType="*/*" />
                 </intent>
                 <!-- If your sends SMS messages -->
                 <intent>
                     <action android:name="android.intent.action.SENDTO" />
                     <data android:scheme="smsto" />
                 </intent>
                 <intent>
                     <action android:name="android.media.action.IMAGE_CAPTURE" />
                 </intent>
      
                 <package android:name="com.facebook.katana" />
             </queries>
      
             <application
                 android:name="androidx.multidex.MultiDexApplication"
                 android:icon="@mipmap/ic_launcher"
                 android:label="@string/app_name"
                 android:roundIcon="@mipmap/ic_launcher_round"
                 android:supportsRtl="true"
                 android:usesCleartextTraffic="true">
                 <receiver
                     android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationBootReceiver"
                     android:exported="false">
                     <intent-filter>
                         <action android:name="android.intent.action.BOOT_COMPLETED" />
                     </intent-filter>
                 </receiver>
                 <receiver
                     android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationReceiver"
                     android:exported="false" />
      
      
                 <meta-data
                     android:name="com.google.android.gms.version"
                     android:value="@integer/google_play_services_version" />
      
                 <meta-data
                     android:name="com.google.firebase.messaging.default_notification_channel_id"
                     android:value="high_importance_channel" />
                 <meta-data
                     android:name="com.google.firebase.messaging.default_notification_icon"
                     android:resource="@drawable/ic_notification" />
                 <meta-data
                     android:name="com.google.firebase.messaging.default_notification_color"
                     android:resource="@color/colorPrimary" />
      
                 <meta-data
                     android:name="com.google.android.geo.API_KEY"
                     android:value="@string/google_api_key" />
      
                 <meta-data
                     android:name="com.facebook.sdk.ApplicationId"
                     android:value="@string/facebook_app_id" />
      
                 <meta-data
                     android:name="com.facebook.sdk.ClientToken"
                     android:value="@string/facebook_client_token" />
      
                 <activity
                     android:name="com.facebook.FacebookActivity"
                     android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
                     android:exported="false"
                     android:label="@string/app_name" />
                 <activity
                     android:name="com.facebook.CustomTabActivity"
                     android:exported="true">
                     <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="@string/fb_login_protocol_scheme" />
                     </intent-filter>
                 </activity>
      
                 <!--<provider android:authorities="com.facebook.app.FacebookContentProvider2226807840719365"
                     android:name="com.facebook.FacebookContentProvider"
                     android:exported="true" />-->
                 <activity
                     android:name="com.yalantis.ucrop.UCropActivity"
                     android:screenOrientation="portrait"
                     android:theme="@style/Theme.AppCompat.Light.NoActionBar" />
      
                 <activity
                     android:name=".MainActivity"
                     android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
                     android:exported="true"
                     android:hardwareAccelerated="true"
                     android:launchMode="singleTop"
                     android:showWhenLocked="true"
                     android:theme="@style/LaunchTheme"
                     android:turnScreenOn="true"
                     android:windowSoftInputMode="adjustResize">
      
                     <meta-data
                         android:name="io.flutter.embedding.android.NormalTheme"
                         android:resource="@style/NormalTheme" />
      
                     <intent-filter>
                         <action android:name="FLUTTER_NOTIFICATION_CLICK" />
                         <category android:name="android.intent.category.DEFAULT" />
                     </intent-filter>
      
                     <meta-data
                         android:name="io.flutter.embedding.android.SplashScreenDrawable"
                         android:resource="@drawable/launch_background" />
                     <intent-filter>
                         <action android:name="android.intent.action.MAIN" />
                         <category android:name="android.intent.category.LAUNCHER" />
                     </intent-filter>
                     <!-- App Links -->
                     <intent-filter android:autoVerify="true">
                         <action android:name="android.intent.action.VIEW" />
                         <category android:name="android.intent.category.DEFAULT" />
                         <category android:name="android.intent.category.BROWSABLE" />
                         <!-- Accepts URIs that begin with https://YOUR_HOST -->
                         <data
                             android:scheme="https"
                             android:host="user-api.slim-surface-app.com" />
                     </intent-filter>
      
                 </activity>
      
                 <meta-data
                     android:name="flutterEmbedding"
                     android:value="2" />
             </application>
      
      
         </manifest>
      
      
    • Dart code updated as:

         void main() {
           runApp(const MyApp());
           initUniLinks();
         }
         void initUniLinks() async {
           // Initialize the UniLinks plugin
           print("Initialize the UniLinks plugin");
           try {
             await getInitialLink();
           } on PlatformException {
             // Handle exception/error as needed
             print("Handle exception/error as needed");
           }
      
           // Listen for incoming deep links
           // Attach a listener to the stream
           print("Listen for incoming deep links");
           linkStream.listen((String? uri) {
             // Handle the deep link URI
             print("Handle the deep link URI");
             print(uri);
      
      
           } , onError: (err) {
             // Handle error, if any
             print("Handle error, if any");
           });
         }
      
      
    • rebuild and reinstall Flutter app on the device for the updates to take effect.

  5. But, now when I hit the domain your-domain.com in browser in device, the same device which is running the Flutter app in debug mode, the device don't identify the DeepLink/AppLink to open the app.

What I'm Expecting

  1. Whenever I open the your-domain.com in my mobile browser the same mobile which is running th Flutter application in debug mode should redirect it to Flutter app and should open the app quickly.

1 Answers1

0

You can test the app by running this command https://docs.flutter.dev/cookbook/navigation/set-up-app-links

adb shell 'am start -a android.intent.action.VIEW \
    -c android.intent.category.BROWSABLE \
    -d "http://<web-domain>/details"' \
    <package name>