无法打开URL ...没有发现要处理意图的活动

发布于 2025-02-10 22:59:04 字数 1370 浏览 1 评论 0原文

我正在尝试在我的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>
)

drawermenu:

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

app.js:

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

我在堆栈的初始屏幕上的第一次使用:

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

尝试重定向到通知屏幕后,我会收到以下错误消息: “错误:无法打开URL'示例:// app/notifications':找不到可以处理意图的活动{act = android.intent.intent.action.view dat = example = example:// app/notifications flg = 0x10000000}”

I'm trying to apply deep linking in my react native app. I followed the documentation and when trying to do the first test I had some problems, I believe it's because of using stack navigator and drawer menu.

Stack:

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

DrawerMenu:

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

App.js:

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

My first useEffect on initial screen of my stack:

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

Right after trying to redirect to the notifications screen I get the following error message:
"Error: Could not open URL 'example://app/notifications': No Activity found to handle Intent { act=android.intent.action.VIEW dat=example://app/notifications flg=0x10000000 }"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

舞袖。长 2025-02-17 22:59:04

而不是使用linking.openurl我使用

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

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

Instead of using Linking.openURL I used linkTo, as in the example below:

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

useEffect(() => {
  linkTo('/notifications');
}, []);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文