Downloading an eSIM programatically in Kotlin

355 Views Asked by At

I am trying to download an eSIM programatically in Kotlin.

val sub = DownloadableSubscription
                .forActivationCode(code /* encodedActivationCode*/)
        val intent = Intent(ACTION_DOWNLOAD_SUBSCRIPTION)
        val callbackIntent = PendingIntent.getBroadcast(
                context, 0 /* requestCode */, intent,
               PendingIntent.FLAG_MUTABLE)
        try {
            mgr.downloadSubscription(sub, true, callbackIntent)
            Log.e(TAG_ESIM, "HERE DLOAD")
        } catch (e: RemoteException) {
            Log.e(TAG_ESIM, e.toString())
        }

I am using the code above downloadSubscription and the logs displayed is this: Multiple enabled profiles is not supported, return default port index downloadSubscription cardId: 0 switchAfterDownload: true portIndex: 0 forceDeactivateSim: false callingPackage: <package_name> isConsentNeededToResolvePortIndex: false shouldResolvePortIndex:true Caller can't manage subscription on target SIM or User consent is required for resolving port index. Ask user's consent first

I added this in AndroidManifest.xml <uses-permission android:name="android.permission.WRITE_EMBEDDED_SUBSCRIPTIONS" tools:ignore="ProtectedPermissions" />

When I tried calling this: Log.d(TAG_ESIM, mgr.euiccInfo.toString())

This is the logs displayed

Does it need to have a setup for slotId or something I missed with regards to the permission or config?

0

There are 0 best solutions below