android - 无法打开 URL...找不到处理 Intent 的 Activity

标签 android react-native react-navigation navigation-drawer deep-linking

我正在尝试在我的 React native 应用程序中应用深度链接。我按照文档进行操作,在尝试进行第一次测试时遇到了一些问题,我相信这是因为使用了堆栈导航器和抽屉菜单。

堆栈:

const SignedInStack = () => (
  <Stack.Navigator>
    <Stack.Screen name='Confluence' component={Confluence} />
    <Stack.Screen name='QRCode' component={Main} />
    <Stack.Screen name='Notifications' component={Notifications} />
  </Stack.Navigator>
)

抽屉菜单:

const DrawerMenu = () => (
  <Drawer.Navigator
    screenOptions={{ headerShown: false }}
    drawerContent={(props) => <CustomDrawerContent {...props} />}
  >
    <Drawer.Screen
      name="SignedInStack"
      component={SignedInStack}
    />
  <Drawer.Navigator/>
);

应用程序.js:

const App = () => (
  <NavigationContainer linking={{
    prefixes: ['example://'],
    config: {
      screens: {
        Notifications: 'notifications',
      },
    },
  }}>
    <DrawerMenu />
  </NavigationContainer>
);

我在堆栈初始屏幕上的第一个 useEffect:

 useEffect(() => {
    Linking.openURL('example://app/notifications');
  }, []);

在尝试重定向到通知屏幕后,我立即收到以下错误消息: “错误:无法打开 URL 'example://app/notifications':找不到处理 Intent { act=android.intent.action.VIEW dat=example://app/notifications flg=0x10000000 } 的 Activity ”

最佳答案

我没有使用 Linking.openURL,而是使用了 linkTo ,如下例所示:

import { useLinkTo } from '@react-navigation/native';
...
const linkTo = useLinkTo();

useEffect(() => {
  linkTo('/notifications');
}, []);

关于android - 无法打开 URL...找不到处理 Intent 的 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72772790/

相关文章:

java - 如何访问android子类中的主要 Activity 上下文

javascript - react-native-modal-dropdown 无法以编程方式更改所选内容

react-native - 将 React-Native-Paper BottomNavigation 与 StackNavigator 相结合

android - 在当前时间上加上一定的时间并写入

Android - 运行时 Dagger 注入(inject)

ios - 带有 React-Navigation 的 React-Native Deeplinks 不起作用

ios - 当端口被阻止时在设备上开发 React Native

javascript - 如何使用 React Navigation 通过深层链接获取组件中的 URI?

reactjs - React Native - React Navigation 在每个页面上显示页眉和页脚

android - AlertDialog.Builder setItems 列表与另一个