linking.getInitialurl()Promise Promise Prome Consolves始终仅在不运行时null

发布于 2025-02-10 17:26:30 字数 2425 浏览 1 评论 0原文

我如何通过ADB运行DeepLink:

adb shell am start -W -a android.intent.action.VIEW -d "https://my.site.com/my/path" com.my.app.package

在此AndroidManifest.xml中:

<manifest ...>
  <queries>
    <intent>
      <action android:name="android.intent.action.VIEW" />
        <data android:scheme="https"/>
    </intent>
  </queries>
   ...
  <application>
    <activity>
      <intent-filter android:autoVerify="true">
        <action android:name="android.intent.action.VIEW" />
          <category android:name="android.intent.category.DEFAULT" />
          <category android:name="android.intent.category.BROWSABLE" />
          <data android:host="my.site.com"
            android:pathPrefix="/my/path"
            android:scheme="https" />
      </intent-filter>
    </activity>
 </application>
</manifest>

在MainActivity.java中,应用程序关闭我正确地链接了,但似乎并未传递给RN层:

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    SplashScreen.show(this);

    Intent intent = getIntent();
    String action = intent.getAction();
    Uri data = intent.getData();

    System.out.println("[MainActivity][onCreate] action="+action);

    if(data != null) {
      System.out.println("[MainActivity][onCreate] data="+data.toString());
    }

    super.onCreate(savedInstanceState);
  }

React Native版本:0.66

在React Antive代码上

Linking.addEventListener('https', handler);
...
Linking.getInitialURL().then(url => {console.log(JSON.stringify(url));}

处理程序与事件触发有关时始终在应用程序中或打开时,我会得到URL recrectyl。

linking.getInitialUrl()始终 null ,事件侦听器在关闭应用程序时永远不会发射。

在iOS上都可以正常工作。

App StateiOSAndroid
打开了
✅✅✅✅✅✅✅✅✅✅✅✅❌✅❌✅❌✅❌✅❌✅✅❌✅❌❌❌❌❌❌✅✅❌❌❌✅✅✅✅✅✅❌❌❌✅❌✅✅✅✅✅✅✅✅✅❌❌❌❌✅❌✅❌❌✅✅✅✅✅✅处理
传递URL

应用程序在Android上关闭时,从深链路

如果需要更多信息,请询问它们,我将更新此问题。

How I run deeplinks via adb:

adb shell am start -W -a android.intent.action.VIEW -d "https://my.site.com/my/path" com.my.app.package

In this AndroidManifest.xml:

<manifest ...>
  <queries>
    <intent>
      <action android:name="android.intent.action.VIEW" />
        <data android:scheme="https"/>
    </intent>
  </queries>
   ...
  <application>
    <activity>
      <intent-filter android:autoVerify="true">
        <action android:name="android.intent.action.VIEW" />
          <category android:name="android.intent.category.DEFAULT" />
          <category android:name="android.intent.category.BROWSABLE" />
          <data android:host="my.site.com"
            android:pathPrefix="/my/path"
            android:scheme="https" />
      </intent-filter>
    </activity>
 </application>
</manifest>

In MainActivity.java with App closed I get the deeplink correctly, but it seems to be not passed to the RN layer:

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    SplashScreen.show(this);

    Intent intent = getIntent();
    String action = intent.getAction();
    Uri data = intent.getData();

    System.out.println("[MainActivity][onCreate] action="+action);

    if(data != null) {
      System.out.println("[MainActivity][onCreate] data="+data.toString());
    }

    super.onCreate(savedInstanceState);
  }

React native version: 0.66

On the React Native code:

Linking.addEventListener('https', handler);
...
Linking.getInitialURL().then(url => {console.log(JSON.stringify(url));}

the handler related to event fires always when app is in background or opened and I get the url correctyl.

The Linking.getInitialURL() resolves always null and the event listener never fires when app is closed.

On iOS all works fine.

App stateiOSAndroid
opened
background
closed

I need React Native handles the URL passed from the deep link when the App is closed on Android.

If more info are needed, please ask for them and I will update this question.

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

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

发布评论

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

评论(2

屌丝范 2025-02-17 17:26:30

路径:android/app/src/main/main/androidmanifest.xml

,您的浏览的刻板标签必须在.mainactivity的活动中

 <activity
    android:exported="true"
    android:name=".MainActivity"
    android:label="@string/app_name"
    android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
    android:launchMode="singleTask"
    android:screenOrientation="portrait" 
    android:windowSoftInputMode="adjustPan">
      <intent-filter android:autoVerify="true">
            <action android:name="android.intent.action.VIEW"/>
            <category android:name="android.intent.category.DEFAULT"/>
            <category android:name="android.intent.category.BROWSABLE"/>
            <data android:host="www.example.com" android:scheme="http"/>
            <data android:host="www.example.com" android:scheme="https"/>
      </intent-filter>
  </activity>

path : android/app/src/main/AndroidManifest.xml

where your intent-filter tag of BROWSABLE must be in activity of .MainActivity

example :

 <activity
    android:exported="true"
    android:name=".MainActivity"
    android:label="@string/app_name"
    android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
    android:launchMode="singleTask"
    android:screenOrientation="portrait" 
    android:windowSoftInputMode="adjustPan">
      <intent-filter android:autoVerify="true">
            <action android:name="android.intent.action.VIEW"/>
            <category android:name="android.intent.category.DEFAULT"/>
            <category android:name="android.intent.category.BROWSABLE"/>
            <data android:host="www.example.com" android:scheme="http"/>
            <data android:host="www.example.com" android:scheme="https"/>
      </intent-filter>
  </activity>
救赎№ 2025-02-17 17:26:30

添加新的新意图:
例如,我的动态链接是: https://myappname.link/k5ucqpw3r2uh1e

强> https

   <activity
        android:name=".MainActivity"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
        android:exported="true"
        android:label="@string/app_name"
        android:launchMode="singleTask"
        android:windowSoftInputMode="adjustResize">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
            <action android:name="android.intent.action.DOWNLOAD_COMPLETE" />
        </intent-filter>
        **<intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="https" />
        </intent-filter>**
    </activity>

Add a fresh new Intent:
for example my dynamic link is: https://myappname.link/k5uCqpw3R2Uh1E

therefor the android:scheme would be https

   <activity
        android:name=".MainActivity"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
        android:exported="true"
        android:label="@string/app_name"
        android:launchMode="singleTask"
        android:windowSoftInputMode="adjustResize">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
            <action android:name="android.intent.action.DOWNLOAD_COMPLETE" />
        </intent-filter>
        **<intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="https" />
        </intent-filter>**
    </activity>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文