eSim Activation Error - EMBEDDED_SUBSCRIPTION_RESULT_ERROR Can't add an Esim subscription

1k Views Asked by At

Configuration:- Device :- Samsung s21 ultra with no sim! OS - 12 (31 API level) Package name = com.example.reactnativesimcardsmanager

Library Reference Link : https://github.com/odemolliens/react-native-sim-cards-manager/tree/develop

For Android code : https://github.com/odemolliens/react-native-sim-cards-manager/tree/develop/android/src/main/java/com/reactnativesimcardsmanager

Case 1 Settings: When library support Target version = 31, compile version 31. Example Target Version = 30 and compile version 30.

Result = When clicking on ACTIVATE ESIM Getting permission popup “Allow ‘package name’ to access your phone’s eUICC Profile?

After clicking on “Allow” getting below error. “2 EMBEDDED_SUBSCRIPTION_RESULT_ERROR - Can't add an Esim subscription”

Case 2 Settings: When library support Target version = 31, compile version 31. Example Target Version = 31 and compile version 31

Result= When clicking on ACTIVATE ESIM Getting permission popup “Allow ‘package name’ to access your phone’s eUICC Profile? With below ERROR. E/Error: 3 EMBEDDED_SUBSCRIPTION_RESULT_RESOLVABLE_ERROR - Can't setup eSim du to Activity error null

After clicking on “Allow” getting below error “2 EMBEDDED_SUBSCRIPTION_RESULT_ERROR - Can't add an Esim subscription”

Reference link :- https://source.android.com/devices/tech/connect/esim-overview

public void setupEsim(ReadableMap config, Promise promise) { initMgr(); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP_MR1) { promise.reject("0", "EuiccManager is not available or before Android 9 (API 28)"); }

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && mgr != null && !mgr.isEnabled()) {
  promise.reject("1", "The device doesn't support a cellular plan (EuiccManager is not available)");
  return;
}

BroadcastReceiver receiver = new BroadcastReceiver() {

  @Override
  public void onReceive(Context context, Intent intent) {
    if (!ACTION_DOWNLOAD_SUBSCRIPTION.equals(intent.getAction())) {
      Log.e("Error", "3 Can't setup eSim du to wrong Intent:" + intent.getAction() + " instead of " + ACTION_DOWNLOAD_SUBSCRIPTION);
      promise.reject("3", "Can't setup eSim du to wrong Intent:" + intent.getAction() + " instead of " + ACTION_DOWNLOAD_SUBSCRIPTION);

      showAlert("Error", "3 Can't setup eSim du to wrong Intent:" + intent.getAction() + " instead of " + ACTION_DOWNLOAD_SUBSCRIPTION);
      return;
    }

    int resultCode = getResultCode();
    if (resultCode == EuiccManager.EMBEDDED_SUBSCRIPTION_RESULT_RESOLVABLE_ERROR && mgr != null) {
      try {

        promise.resolve(3);
        PendingIntent callbackIntent = PendingIntent.getBroadcast(mReactContext, 3,
          new Intent(ACTION_DOWNLOAD_SUBSCRIPTION), PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE);
        mgr.startResolutionActivity(mReactContext.getCurrentActivity(), 3, intent, callbackIntent);
      } catch (Exception e) {
        e.printStackTrace();
        Log.e("Error", "3 EMBEDDED_SUBSCRIPTION_RESULT_RESOLVABLE_ERROR - Can't setup eSim du to Activity error" + e.getLocalizedMessage());
        promise.reject("3", "EMBEDDED_SUBSCRIPTION_RESULT_RESOLVABLE_ERROR - Can't setup eSim du to Activity error" + e.getLocalizedMessage());
        showAlert("Error", "3 EMBEDDED_SUBSCRIPTION_RESULT_RESOLVABLE_ERROR - Can't setup eSim du to Activity error" + e.getLocalizedMessage());
      }
    } else if (resultCode == EuiccManager.EMBEDDED_SUBSCRIPTION_RESULT_OK) {
      promise.resolve(true);

      Log.e("Success", "EMBEDDED_SUBSCRIPTION_RESULT_OK");
      showAlert("Success", "Success : EMBEDDED_SUBSCRIPTION_RESULT_OK");
    } else if (resultCode == EuiccManager.EMBEDDED_SUBSCRIPTION_RESULT_ERROR) {

      Log.e("Error", "2 EMBEDDED_SUBSCRIPTION_RESULT_ERROR - Can't add an Esim subscription");
      promise.reject("2", "EMBEDDED_SUBSCRIPTION_RESULT_ERROR - Can't add an Esim subscription");
      showAlert("Error", "2 EMBEDDED_SUBSCRIPTION_RESULT_ERROR - Can't add an Esim subscription");

      int detailedCode = intent.getIntExtra(EuiccManager.EXTRA_EMBEDDED_SUBSCRIPTION_DETAILED_CODE, 0);
      Log.e("detailedCode", detailedCode+"");

    } else {

      Log.e("Error", "3 Can't add an Esim subscription due to unknown error, resultCode is:" + String.valueOf(resultCode));
      promise.reject("3", "Can't add an Esim subscription due to unknown error, resultCode is:" + String.valueOf(resultCode));
      showAlert("Error", "3 Can't add an Esim subscription due to unknown error, resultCode is:" + String.valueOf(resultCode));
    }
  }
};

mReactContext.registerReceiver(
  receiver,
  new IntentFilter(ACTION_DOWNLOAD_SUBSCRIPTION),
  null,
  null);

DownloadableSubscription sub = DownloadableSubscription.forActivationCode(

  config.getString("confirmationCode"));

PendingIntent callbackIntent = PendingIntent.getBroadcast(
  mReactContext,
  0,
  new Intent(ACTION_DOWNLOAD_SUBSCRIPTION),
  PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE);

mgr.downloadSubscription(sub, true, callbackIntent);

}

2

There are 2 best solutions below

1
On

What are the detailedCode and operationCode you are receiving in all cases? I have a similar issue but the detailedCode and operationCode are never set.

1
On

It's the same for me, when activating LUI Do you want to allow the application to add eSim? After confirmation immediately reject null, if after that you press again - confirm reset eSim 1? You confirm and then eSim is activated, I don’t understand how it should work

  @RequiresApi(api = Build.VERSION_CODES.P)
  private void handleResolvableError(Intent intent, PluginCall call) {
    PendingIntent callbackIntent = PendingIntent.getBroadcast(
        getContext(),
        Activity.RESULT_OK/* requestCode -1*/,
        intent,
        Build.VERSION.SDK_INT >= Build.VERSION_CODES.S ? PendingIntent.FLAG_MUTABLE : PendingIntent.FLAG_UPDATE_CURRENT);
    try {
      mgr.startResolutionActivity(
          getActivity(),
          Activity.RESULT_OK /* requestCode -1*/,
          intent,
          callbackIntent);
    } catch (IntentSender.SendIntentException e) {
      Log.d("CODE_LOG_E", String.valueOf(e.getLocalizedMessage()));
    }
  }