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

Expo开发React Native应用:分享链接无法唤起安卓应用求助

Fixing Deep Linking Issues with Expo on Android

Hey there! Let's work through this deep linking problem you're hitting with your Expo React Native app. I've looked over your code and setup, so here are the key fixes and checks to get your app opening from shared links:

1. Verify Your Scheme is Properly Configured in app.json

This is the most common oversight! You've referenced the scheme nxet in your code, but you need to explicitly define it in your project's app.json so Expo knows to register it with Android:

{
  "expo": {
    "scheme": "nxet",
    // Keep all your existing Expo configs here
    "name": "Your App Name",
    "slug": "your-app-slug",
    "android": {
      "package": "com.your.app.package" // Make sure this is set too
    }
  }
}

After updating app.json, restart your Expo development server—this change won't take effect until you do.

2. Fix Scope Issues in Your Linking Event Handler

Looking at your handleOpenURL method, the scheme variable you're using isn't accessible! You declared it inside componentDidMount with let, which limits its scope to that function. Move it to a class-level property so your handler can access it:

class App extends React.Component {
  // Define scheme at the class level
  scheme = 'nxet';

  handleOpenURL(event) {
    if (event.url && event.url.indexOf(`${this.scheme}://`) === 0) {
      crossroads.parse(event.url.slice(this.scheme.length + 3));
    }
  }

  componentDidMount() {
    Expo.Linking.getInitialURL()
      .then(url => {
        console.log("App.js getInitialURL Triggered")
        // Uncomment this line to handle links that opened the app initially
        if (url) this.handleOpenURL({ url });
      })
      .catch(error => console.error(error));
    Linking.addEventListener('url', this.handleOpenURL);
  }

  componentWillUnmount() {
    Linking.removeEventListener('url', this.handleOpenURL);
  }

  // Rest of your component code...
}

I also uncommented the handleOpenURL call in getInitialURL—this ensures your app handles links that were used to launch it directly.

3. Test Your Scheme the Right Way on Android

Directly typing your custom scheme (like nxet://) into Chrome's address bar often gets treated as a search query instead of a deep link. Try these more reliable testing methods:

  • Use an ADB command: Run this in your terminal to trigger the link directly (replace com.your.app.package with the package name from your app.json):
    adb shell am start -W -a android.intent.action.VIEW -d "nxet://" com.your.app.package
    
  • Create a test HTML link: Make a simple HTML file with this line, host it somewhere, and open it in your Android browser:
    <a href="nxet://">Open My App</a>
    
    Tapping this link should prompt you to open your app.

Double-check that Expo.Linking.makeUrl() is generating the right link. Add a console.log to verify:

const deepLink = Expo.Linking.makeUrl();
console.log('Generated deep link:', deepLink); // Should log "nxet://" (or with path if you added one)

Share.share({ 
  message: "Click Here to View More! " + deepLink, 
  url: deepLink, 
  title: 'Sufiyaan has invited you to join this activity'
})
// ... rest of your share code

Ensure the shared link starts with nxet://—if it doesn't, there might be a misconfiguration in your Expo setup.

5. Check for Android-Specific Share Behavior

Some apps (like WhatsApp) might render custom scheme links as plain text instead of clickable links. For better compatibility, you could also set up App Links (using a hosted assetlinks.json file) with HTTPS links that redirect to your custom scheme, but that's an extra step once you get basic deep linking working.

Give these steps a try—most likely the missing app.json scheme config or scope issue in your handler is causing the problem.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.27 09:33:36