深层链接后如何重新启动本机应用程序

时间:2020-04-24 22:15:07

标签: android react-native

我有一个想要通过深层链接进行付款的应用。我在应用程序的开头有一些api,因此从付款中回来后,我想再次启动应用程序,这是我的链接抛出网址

const goToFeedback = () => {
    setLoading(true);
    sendTransactionPay({
      walletUrl,
      walletId,
      callback: id => {
        Linking.canOpenURL(`${paymentUrl}\/${id}`).then(supported => {
          if (supported) {
            Linking.openURL(`${paymentUrl}\/${id}`);
          } else {
            changeEvent({
              showModal: false,
              modalMessage: 'error',
              info: false,
            });
          }
        });
      },
    });
  };

很遗憾,从付款网址返回后,当前组件已经显示。这是我的清单

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

1 个答案:

答案 0 :(得分:1)

使用此库(不要忘记进行本机链接):

https://www.npmjs.com/package/react-native-restart

然后,您可以使用一个功能重新启动rn应用:

#include <stdio.h>
#include <stdlib.h>

void check_if_valid_value(int range)
{
        if (range != 2) 
        {
                printf("You have not entered two integers.\n");
                exit(1);
        }
}          

void reorder_range(int *p, int *q)
{
        int aux;

        if (*p > *q)
        {
                aux = *p;
                *p = *q;
                *q = aux;
        }
}

void dothesum(int p,int q)
{  
        int i, sum;
        sum = 0;

        for (i = p; i <= q; ++i)
        {
                sum=sum+i;
                printf("%d\n", sum);
        }

}

int main(void)
{

        int range, p, q;

        printf("Enter two integers:");
        range=scanf("%d%d",&p,&q);

        check_if_valid_value(range);
        reorder_range(&p, &q);
        dothesum(p,q);

        return 0;
}