Skip to content
The Chat Archive
qwen3-30b-a3b· Alibaba (Qwen) LMArena Human Preference 140K

how can a url get opened in an app on mobile or desktop

  1. User

    how can a url get opened in an app on mobile or desktop

  2. Assistant

    To open a URL in an app (mobile or desktop), you can use custom URL schemes, Universal Links/App Links, or web-based approaches. Here's how it works:


    1. Custom URL Schemes (Legacy)

    • Format: myapp://path?query=parameters
    • How it works:
      • The app registers a custom scheme (e.g., myapp://) in its configuration.
      • When a user clicks a link like myapp://open?item=123, the OS checks if the app is installed and opens it.
    • Example:
      • A link like myapp://profile/123 could open a user profile in the app.
    • Limitations:
      • Not secure (can be intercepted).
      • Requires the app to be installed.
      • Not supported by all platforms (e.g., iOS has restrictions).

    2. Universal Links (iOS)

    • Format: https://example.com/path?query=parameters
    • How it works:
      • The app links to a HTTPS URL (e.g., https://example.com/open).
      • The app claims ownership of the domain via a .well-known/assetlinks.json file.
      • When the user clicks the link, iOS checks if the app is installed and opens it.
    • Example:
      • A link like https://example.com/profile/123 opens the app if installed.
    • Requirements:
      • HTTPS must be used.
      • The app must include the domain in its Info.plist file.

    3. App Links (Android)

    • Format: https://example.com/path?query=parameters
    • How it works:
      • Similar to Universal Links but for Android.
      • The app claims ownership of the domain via a <intent-filter> in its manifest.
      • When the user clicks the link, Android checks if the app is installed and opens it.
    • Example:
      • A link like https://example.com/share?text=hello opens the app if installed.
    • Requirements:
      • HTTPS must be used.
      • The app must declare the domain in its AndroidManifest.xml.

    4. Web-Based Apps (Progressive Web Apps)

    • Format: https://example.com
    • How it works:
      • A PWA can be installed on a device and behaves like a native app.
      • When a user clicks a link to the PWA's URL, it opens in the app (if installed).
    • Example:
      • A link like https://example.com/dashboard opens the PWA if installed.
    • Requirements:
      • The PWA must have a valid manifest file and service worker.

    5. Desktop Apps (Custom Schemes)

    • Format: myapp://path?query=parameters
    • How it works:
      • Desktop apps (e.g., Electron, native apps) can register custom schemes.
      • When a user clicks a link like myapp://open, the OS opens the app.
    • Example:
      • A link like myapp://settings opens the app's settings screen.
    • Limitations:
      • Requires the app to be installed.
      • Not secure (same as mobile custom schemes).

    6. Deep Linking in Mobile Apps

    • How it works:
      • Apps can use deep links to navigate directly to specific content (e.g., a product page, user profile).
      • Example: https://example.com/product/123 opens the product page in the app.
    • Implementation:
      • Use Universal Links/App Links or custom schemes.
      • Apps must handle the URL parameters (e.g., parse product/123 to show the product).

    7. Fallback Behavior

    • If the app is not installed, the OS typically opens the URL in the default browser.
    • Example: A link like myapp://profile/123 opens https://example.com/profile/123 in the browser if the app is missing.

    Example Code (iOS Universal Link)

    1. Create assetlinks.json:

      [{
        "relation": ["delegate_permission/common.get_app_link"],
        "target": {
          "namespace": "web",
          "site": "https://example.com"
        }
      }]
      

      Upload this file to https://example.com/.well-known/assetlinks.json.

    2. Update Info.plist:

      <key>CFBundleURLTypes</key>
      <array>
        <dict>
          <key>CFBundleURLSchemes</key>
          <array>
            <string>myapp</string>
          </array>
        </dict>
      </array>
      

    Example Code (Android App Link)

    1. Add to AndroidManifest.xml:
      <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" />
        <data android:scheme="https" android:host="example.com" />
      </intent-filter>
      

    Summary Table

    MethodMobileDesktopNotes
    Custom Schemes✅✅Not secure, requires app to be installed
    Universal Links✅❌iOS only, requires HTTPS
    App Links✅❌Android only, requires HTTPS
    PWAs✅✅Works in browsers and as installed apps
    Deep Links✅✅Navigates to specific content within the app

    Let me know if you want help implementing a specific method (e.g., Universal Links or custom schemes)!

  3. User

    On android, if I click on e.g. a youtube link in discord it usually takes me to the web browser, which offers to open the link in the app Grayjay Meanwhile in other apps if I click the same link it directly opens the video in Grayjay

    please explain the difference

  4. Assistant

    The behavior you're seeing depends on how apps register to handle URLs (like YouTube links) and how Android's system resolves these links. Here's a breakdown of the difference between Discord and other apps:


    1. Discord Opens the Link in the Browser First

    • Why?
      Discord might not directly support deep linking to the Grayjay app. Instead, it opens the link in the web browser (or a built-in WebView) because:

      • Discord doesn't have a configured intent filter or App Link to directly launch Grayjay.
      • It treats the link as a generic URL (e.g., https://youtube.com/...) and lets the system decide how to handle it.
      • The browser then checks if any app (like Grayjay) can handle the URL via App Links or custom schemes.
    • What happens next?
      The browser detects that Grayjay is installed and asks:

      "Open this link in Grayjay?"
      This is a fallback mechanism when the system can't directly route the link to the app.


    2. Other Apps Open the Link Directly in Grayjay

    • Why?
      Apps that natively support deep linking (like some video players or social media apps) can directly launch Grayjay without involving the browser. This happens because:

      • The app uses App Links (HTTPS-based) or custom schemes (e.g., grayjay://) to register with Android.
      • When the app detects a YouTube link (e.g., https://youtube.com/...), it uses a deep link to pass the URL to Grayjay.
    • How it works:

      • The app checks if Grayjay is installed and supports the URL format.
      • If yes, it directly launches Grayjay with the video ID or URL embedded in the deep link (e.g., grayjay://video/12345).
      • No browser is involved, so the user sees the video in Grayjay immediately.

    Key Differences:

    FeatureDiscordOther Apps
    URL HandlingOpens link in browser (fallback)Uses deep links or App Links to open directly in Grayjay
    App IntegrationNo direct integration with GrayjayConfigured to use Grayjay's deep links or App Links
    User ExperienceBrowser prompts to open in GrayjayDirectly opens in Grayjay without prompts

    Why the Browser Is a Mediator

    • Android's default behavior is to open unknown URLs in the browser. If the browser detects that an app (like Grayjay) can handle the URL, it offers to open it.
    • Apps that don’t support App Links or custom schemes will always fall back to the browser.

    How Apps Register to Handle URLs

    1. App Links (Recommended):

      • Require HTTPS and a digitalassetlinks.json file (e.g., https://example.com/.well-known/assetlinks.json).
      • Example: A YouTube link like https://youtube.com/watch?v=123 could be handled by Grayjay if it’s configured to support this domain.
    2. Custom Schemes (Legacy):

      • Use a custom protocol like grayjay://.
      • Example: grayjay://video/123 would open Grayjay directly.
      • Limitation: Not secure and often blocked by modern browsers.
    3. Intent Filters (Android):

      • Apps can declare in their AndroidManifest.xml that they can handle specific URL patterns (e.g., youtube.com).
      • Example: An app might declare:
        <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="youtube.com" />
        </intent-filter>
        

    Why Discord Doesn’t Use This

    • Discord may not have implemented deep linking to Grayjay. It treats YouTube links as generic URLs and lets the system decide (via the browser).
    • Other apps (like video players or social media apps) might have explicitly configured App Links or intent filters to open Grayjay directly.

    Summary

    • Discord opens the link in the browser because it doesn’t directly support Grayjay’s deep links.
    • Other apps use App Links or custom schemes to bypass the browser and open Grayjay directly.
    • The browser acts as a fallback to handle unknown URLs and check for app integrations.

    If you want to fix this, you could:

    • Ask Discord to add support for Grayjay’s deep links.
    • Use a third-party app (like Link Shell or App Links Manager) to force links to open in Grayjay.

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