onActivityResult方法永远不会触发

时间:2019-06-05 16:49:04

标签: android react-native

我有一个本地Android应用程序,它启动了react-native应用程序。本地android应用程序的工作原理是创建一种意图来加载运行react-native捆绑包的活动。效果很好,但我尝试使用卡片扫描插件,该插件会在返回的所有引用Activity activity = getCurrentActivity();之上创建自己的Intent。通过执行以下操作,我验证了此返回的活动与react-native正在其上运行的活动的引用相同,

Activity activity = getCurrentActivity();
Boolean test = MobileSDK.getInstance().getRef().get() == activity;
Log.e("WOW", test.toString());

该代码段来自桥接器上暴露的功能,以启动卡扫描活动。

  @ReactMethod
  public void scanCard(ReadableMap config, Promise promise) {
    this.promise = promise;
    Activity activity = getCurrentActivity();
    Boolean test = MobileSDK.getInstance().getRef().get() == activity;
    Log.e("WOW", test.toString());
    Intent scanIntent = new Intent(activity, CardIOActivity.class);
    scanIntent.putExtra(CardIOActivity.EXTRA_REQUIRE_EXPIRY, true);
    scanIntent.putExtra(CardIOActivity.EXTRA_REQUIRE_CVV, true);
    parseConfig(config, scanIntent);
    if (activity != null) {
      activity.startActivityForResult(scanIntent, CARD_IO_SCAN);
    }
  }

这导致 WOW : true

因此,当卡片扫描模块(使用maven插入时,我实际上无法访问它的代码)时,关闭它的意图是,这应该会触发但不是。

@Override
  public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) {
    Log.e("HELLOOOOO", "B4");
    if (requestCode != CARD_IO_SCAN) {
      return;
    }

    if (data != null && data.hasExtra(CardIOActivity.EXTRA_SCAN_RESULT)) {
      CreditCard scanResult = data.getParcelableExtra(CardIOActivity.EXTRA_SCAN_RESULT);
      WritableMap res = Arguments.createMap();
      res.putString("cardType", scanResult.getCardType().getDisplayName(data.getStringExtra(CardIOActivity.EXTRA_LANGUAGE_OR_LOCALE)));
      res.putString("cardNumber", scanResult.cardNumber);
      res.putString("redactedCardNumber", scanResult.getRedactedCardNumber());
      res.putInt("expiryMonth", scanResult.expiryMonth);
      res.putInt("expiryYear", scanResult.expiryYear);
      res.putString("cvv", scanResult.cvv);
      res.putString("postalCode", scanResult.postalCode);
      res.putString("cardholderName", scanResult.cardholderName);
      Log.e("HELLOOOOOOOO", res.toString());
      this.promise.resolve(res);
    } else {
      Log.e("HELLOOOOOOOO", "FAIL");
      this.promise.reject("user_cancelled", "The user cancelled");
    }
  }

当本机应用程序作为独立应用程序运行时,将运行卡扫描实用程序,但当将其加载到另一个Android应用程序中时,则不会运行。

我在网上寻找解决方案,人们建议对Android.manifest文件进行更改,但是我看不到他们建议的部分会给我带来麻烦。

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myapplication">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

    <uses-permission android:name="android.permission.INTERNET" />

</manifest>

0 个答案:

没有答案