Expo技术咨询:分享网页链接时我的应用未显示在分享列表中
Hey Chandra, let's get your Expo Android app showing up in the browser's share menu when sharing links like Google's URL. Here's a step-by-step breakdown to fix this:
app.json Android uses intent filters to recognize which apps can handle specific types of shared content. You need to configure this in your Expo project's app.json to tell the system your app accepts web links shared as plain text.
Add this snippet inside the expo.android section:
{ "expo": { "android": { "intentFilters": [ { "action": "android.intent.action.SEND", "data": [ { "mimeType": "text/plain" } ], "category": [ "android.intent.category.DEFAULT" ] } ] } } }
This filter tells Android your app can receive text/plain content—most web links are shared in this format, so this will cover your use case.
Even if your app appears in the share menu, it won't do anything useful unless you process the incoming link. Use Expo's Linking API to capture and handle the shared URL.
Add this code to your main app component:
import { Linking, useEffect } from 'react-native'; export default function App() { useEffect(() => { // Check for a link when the app first opens const checkInitialLink = async () => { const url = await Linking.getInitialURL(); if (url) { // Do something with the shared URL—e.g., display it or navigate to a screen console.log('Received shared link:', url); } }; checkInitialLink(); // Listen for future share events while the app is running const linkSubscription = Linking.addEventListener('url', (event) => { console.log('Received shared link:', event.url); // Handle the link here }); // Clean up the listener when the component unmounts return () => linkSubscription.remove(); }, []); // Rest of your app code... }
Important: Expo Go doesn't support custom intent filters, so you can't test this with the Expo Go app. You need to create a custom development build or production build using EAS Build.
Run this command to start the build process:
eas build --platform android
Once the build finishes, download and install the APK on your Android device.
- Double-check your
app.jsonsyntax: Make sure the intent filter is nested correctly underexpo.android—a typo here will break everything. - Uninstall old versions: Sometimes cached app data can prevent new intent filters from working. Uninstall any previous versions of your app before installing the new build.
- Add extra mime types (if needed): If you want to handle other share types, add
text/uri-listto thedata.mimeTypearray for more robust link support.
内容的提问来源于stack exchange,提问作者Chandra Bhushan

