You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何查找Android应用的应用名/Intent名称,实现跨应用启动自有应用

How to Set Up a Custom URL Scheme for Your App (So Other Apps Can Launch It)

Hey there! Let me break down exactly how to set up a custom URL scheme for your app—this is the same mechanism that powers market:// for Google Play and instagram:// for Instagram. The "app name" you're trying to use isn't something that exists by default; you have to manually define this scheme in your app's configuration.

Android Setup

To get myapp://login working on Android, you need to add an intent filter to the Activity you want to launch (like your LoginActivity) in your AndroidManifest.xml:

<activity android:name=".LoginActivity">
    <!-- Intent filter to handle custom URL scheme -->
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        
        <!-- This defines your custom scheme and host -->
        <data
            android:scheme="myapp"
            android:host="login" />
    </intent-filter>
</activity>
  • Testing: You can test this right away with an ADB command:

    adb shell am start -W -a android.intent.action.VIEW -d "myapp://login" com.your.app.package
    

    Or try typing myapp://login into a mobile browser—if your app is installed, it should launch directly to the LoginActivity.

  • Pro Tip: Use a unique scheme to avoid conflicts with other apps. Instead of just myapp, consider using your app's reverse domain (e.g., com.yourcompany.myapp) as the scheme.

iOS Setup

For iOS, you'll configure the scheme in your project's Info.plist and add code to handle the incoming URL:

  1. Add the URL Scheme:

    • Open Xcode, go to your project's Info.plist
    • Right-click and select "Add Row", then choose URL types
    • Expand URL types, add an entry, set URL Schemes to myapp (or your unique scheme), and fill Identifier with your app's Bundle ID.
  2. Handle the URL:
    In either your SceneDelegate (iOS 13+) or AppDelegate, add code to route the URL to the right screen:

    // SceneDelegate.swift (iOS 13+)
    func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
        guard let url = URLContexts.first?.url else { return }
        
        if url.scheme == "myapp" && url.host == "login" {
            // Navigate to your LoginViewController here
            let loginVC = LoginViewController()
            // Add your navigation logic (e.g., push to navigation stack)
        }
    }
    
    // AppDelegate.swift (older iOS versions)
    func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
        if url.scheme == "myapp" && url.host == "login" {
            // Handle login screen navigation
            return true
        }
        return false
    }
    
  • Testing: Open Safari on your simulator/device and type myapp://login—your app should launch and trigger the navigation logic you added.

Key Notes

  • Always ensure your scheme is unique to avoid collisions with other apps. Using your app's Bundle ID as part of the scheme is a safe bet.
  • If the app isn't installed, tapping the custom URL will fail—you can add a fallback (like redirecting to your app store page) for web links.
  • Some browsers or apps might block custom schemes, so test thoroughly across different launch sources.

Hope this gets your custom URL scheme working smoothly! If you run into platform-specific issues, feel free to dive deeper into the details for your OS.

内容的提问来源于stack exchange,提问作者GKV

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.11 08:31:53