如何查找Android应用的应用名/Intent名称,实现跨应用启动自有应用
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.packageOr try typing
myapp://logininto 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:
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, setURL Schemestomyapp(or your unique scheme), and fillIdentifierwith your app's Bundle ID.
- Open Xcode, go to your project's
Handle the URL:
In either yourSceneDelegate(iOS 13+) orAppDelegate, 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

