Skip to content
TheChatArchiveThe Chat Archive
Mistralmistral-small-3.1-24b-instruct-2503· Mistral AIHugging Face LMArena Human Preference 140K

is this deeplinking ok or something is wrong? It does not work correctly. It opens the…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Geminigemini-2.5-pro’s answer.
  1. User

    is this deeplinking ok or something is wrong? It does not work correctly. It opens the app but not correct link: package se.vl.app;

    import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.nfc.NfcAdapter; import android.util.Log; import android.view.View; import android.webkit.WebSettings;

    import com.getcapacitor.BridgeActivity; import com.getcapacitor.JSObject; import se.vl.app.plugins.MtbPlugin; import se.vl.app.plugins.ZoomPlugin;

    import org.json.JSONObject;

    public class MainActivity extends BridgeActivity { private static final String TAG = "MainActivity"; private NfcAdapter nfcAdapter; public float initialSystemFontScale;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        registerPlugin(MtbPlugin.class);
        registerPlugin(ZoomPlugin.class);
        super.onCreate(savedInstanceState);
         nfcAdapter = NfcAdapter.getDefaultAdapter(getApplicationContext());
    
         if (nfcAdapter != null) {
             disableNFC();
             IntentFilter filter = new IntentFilter(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED);
             if (Build.VERSION.SDK_INT >= 34 && getApplicationInfo().targetSdkVersion >= 34) {
                this.registerReceiver(NFCReceiver, filter, Context.RECEIVER_EXPORTED);
             } else {
                 this.registerReceiver(NFCReceiver, filter);
             }
         }
    
        // Emit text zoom by plugin, ignore native scaling
        WebSettings settings = bridge.getWebView().getSettings();
        initialSystemFontScale = settings.getTextZoom() / 100.0f;
        settings.setTextZoom(100);
        settings.setSupportZoom(false);
    
        View decorView = getWindow().getDecorView();
       decorView.getViewTreeObserver().addOnWindowFocusChangeListener(hasFocus -> {
            Log.d(TAG, "DecorView focus changed: hasFocus=" + hasFocus);
            emitAppFocusEvent(hasFocus);
       });
    
        handleAppLink(getIntent());
    }
    
    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        handleAppLink(intent);
    }
    
    private void handleAppLink(Intent intent) {
        String action = intent.getAction();
        Uri data = intent.getData();
    
        if (Intent.ACTION_VIEW.equals(action) && data != null) {
            String url = data.toString();
    
            if (url.contains("al_applink_data")) {
                url = extractTargetUrlFromFacebookAppLink(url);
            }
    
            if (bridge != null) {
                JSObject urlObject = new JSObject();
                urlObject.put("url", url);
                bridge.triggerWindowJSEvent("appUrlOpen", urlObject.toString());
                Log.d(TAG, "Deep link processed: " + url);
            }
        }
    }
    
    private String extractTargetUrlFromFacebookAppLink(String appLinkUrl) {
        try {
            Uri uri = Uri.parse(appLinkUrl);
            String alData = uri.getQueryParameter("al_applink_data");
            if (alData != null) {
                JSONObject json = new JSONObject(alData);
                return json.optString("target_url", appLinkUrl);
            }
        } catch (Exception e) {
            Log.e(TAG, "Error parsing Facebook App Link", e);
        }
        return appLinkUrl;
    }
    
    private void emitAppFocusEvent(boolean hasFocus) {
        JSObject eventData = new JSObject();
        eventData.put("hasFocus", hasFocus);
        bridge.triggerWindowJSEvent("appFocusChanged", eventData.toString());
        Log.d(TAG, "Emitted appFocusChanged event with hasFocus=" + hasFocus);
    }
    
    
    private final BroadcastReceiver NFCReceiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                final String action = intent.getAction();
    
                if (action.equals(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED)) {
                    final int state = intent.getIntExtra(NfcAdapter.EXTRA_ADAPTER_STATE,
                        NfcAdapter.STATE_OFF);
                    switch (state) {
                        case NfcAdapter.STATE_OFF:
                        case NfcAdapter.STATE_TURNING_OFF:
                            break;
                        case NfcAdapter.STATE_ON:
                        case NfcAdapter.STATE_TURNING_ON:
                            disableNFC();
                            break;
                    }
                }
            }
        };
    
    @Override
    public void onDestroy() {
       super.onDestroy();
       this.unregisterReceiver(NFCReceiver);
    }
    
    
    private void disableNFC() {
        nfcAdapter.enableReaderMode(this, null, NfcAdapter.STATE_OFF, null);
    }
    

    }

  2. Mistral Assistant

    Your code for handling deep links in an Android application using Capacitor seems mostly correct, but there are a few areas where issues might arise. Let's go through some potential problems and solutions:

    1. Intent Filter in Manifest: Ensure that you have the correct intent filters in your AndroidManifest.xml to handle deep links. For example:

      <activity
          android:name=".MainActivity"
          android:launchMode="singleTask">
          <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="https" android:host="yourdomain.com" />
          </intent-filter>
      </activity>
      

      Replace yourdomain.com with your actual domain.

    2. Handling Deep Links: Your handleAppLink method seems correct, but ensure that the bridge is properly initialized before calling triggerWindowJSEvent.

    3. Logging and Debugging: Add more logging to understand where the issue might be. For example, log the intent and data in handleAppLink.

    4. Facebook App Links: Ensure that the extractTargetUrlFromFacebookAppLink method correctly parses the URL. You might want to add more logging here as well.

    5. NFC Handling: The NFC handling code seems unrelated to deep linking, but ensure it doesn't interfere with the deep link handling.

    Here is a revised version of your MainActivity with additional logging and checks:

    package se.vl.app;
    
    import android.net.Uri;
    import android.os.Build;
    import android.os.Bundle;
    import android.content.BroadcastReceiver;
    import android.content.Context;
    import android.content.Intent;
    import android.content.IntentFilter;
    import android.nfc.NfcAdapter;
    import android.util.Log;
    import android.view.View;
    import android.webkit.WebSettings;
    
    import com.getcapacitor.BridgeActivity;
    import com.getcapacitor.JSObject;
    import se.vl.app.plugins.MtbPlugin;
    import se.vl.app.plugins.ZoomPlugin;
    
    import org.json.JSONObject;
    
    public class MainActivity extends BridgeActivity {
        private static final String TAG = "MainActivity";
        private NfcAdapter nfcAdapter;
        public float initialSystemFontScale;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            registerPlugin(MtbPlugin.class);
            registerPlugin(ZoomPlugin.class);
            super.onCreate(savedInstanceState);
            nfcAdapter = NfcAdapter.getDefaultAdapter(getApplicationContext());
    
            if (nfcAdapter != null) {
                disableNFC();
                IntentFilter filter = new IntentFilter(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED);
                if (Build.VERSION.SDK_INT >= 34 && getApplicationInfo().targetSdkVersion >= 34) {
                    this.registerReceiver(NFCReceiver, filter, Context.RECEIVER_EXPORTED);
                } else {
                    this.registerReceiver(NFCReceiver, filter);
                }
            }
    
            // Emit text zoom by plugin, ignore native scaling
            WebSettings settings = bridge.getWebView().getSettings();
            initialSystemFontScale = settings.getTextZoom() / 100.0f;
            settings.setTextZoom(100);
            settings.setSupportZoom(false);
    
            View decorView = getWindow().getDecorView();
            decorView.getViewTreeObserver().addOnWindowFocusChangeListener(hasFocus -> {
                Log.d(TAG, "DecorView focus changed: hasFocus=" + hasFocus);
                emitAppFocusEvent(hasFocus);
            });
    
            handleAppLink(getIntent());
        }
    
        @Override
        protected void onNewIntent(Intent intent) {
            super.onNewIntent(intent);
            handleAppLink(intent);
        }
    
        private void handleAppLink(Intent intent) {
            String action = intent.getAction();
            Uri data = intent.getData();
    
            Log.d(TAG, "Handling app link: action=" + action + ", data=" + data);
    
            if (Intent.ACTION_VIEW.equals(action) && data != null) {
                String url = data.toString();
    
                if (url.contains("al_applink_data")) {
                    url = extractTargetUrlFromFacebookAppLink(url);
                }
    
                if (bridge != null) {
                    JSObject urlObject = new JSObject();
                    urlObject.put("url", url);
                    bridge.triggerWindowJSEvent("appUrlOpen", urlObject.toString());
                    Log.d(TAG, "Deep link processed: " + url);
                } else {
                    Log.e(TAG, "Bridge is null, cannot trigger event");
                }
            } else {
                Log.d(TAG, "Invalid action or data: action=" + action + ", data=" + data);
            }
        }
    
        private String extractTargetUrlFromFacebookAppLink(String appLinkUrl) {
            try {
                Uri uri = Uri.parse(appLinkUrl);
                String alData = uri.getQueryParameter("al_applink_data");
                if (alData != null) {
                    JSONObject json = new JSONObject(alData);
                    return json.optString("target_url", appLinkUrl);
                }
            } catch (Exception e) {
                Log.e(TAG, "Error parsing Facebook App Link", e);
            }
            return appLinkUrl;
        }
    
        private void emitAppFocusEvent(boolean hasFocus) {
            JSObject eventData = new JSObject();
            eventData.put("hasFocus", hasFocus);
            bridge.triggerWindowJSEvent("appFocusChanged", eventData.toString());
            Log.d(TAG, "Emitted appFocusChanged event with hasFocus=" + hasFocus);
        }
    
        private final BroadcastReceiver NFCReceiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                final String action = intent.getAction();
    
                if (action.equals(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED)) {
                    final int state = intent.getIntExtra(NfcAdapter.EXTRA_ADAPTER_STATE,
                            NfcAdapter.STATE_OFF);
                    switch (state) {
                        case NfcAdapter.STATE_OFF:
                        case NfcAdapter.STATE_TURNING_OFF:
                            break;
                        case NfcAdapter.STATE_ON:
                        case NfcAdapter.STATE_TURNING_ON:
                            disableNFC();
                            break;
                    }
                }
            }
        };
    
        @Override
        public void onDestroy() {
            super.onDestroy();
            this.unregisterReceiver(NFCReceiver);
        }
    
        private void disableNFC() {
            nfcAdapter.enableReaderMode(this, null, NfcAdapter.STATE_OFF, null);
        }
    }
    

    Additional Steps:

    1. Check Intent Filters: Ensure that the intent filters in your AndroidManifest.xml are correctly set up to handle the deep links.
    2. Test with Different URLs: Try different URLs to see if the issue is specific to certain types of deep links.
    3. Check for Errors: Look at the logs for any errors or warnings that might give more context about why the deep link is not working as expected.

    By adding more logging and ensuring that the intent filters are correctly set up, you should be able to diagnose and fix the issue with deep linking in your application.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.