You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android端eSIM实现问题:确认弹窗点击后SIM未安装

eSIM安装问题排查

我正在Android应用中实现eSIM功能,代码运行时会弹出“允许运营商下载SIM”的对话框,但点击“是”后,SIM并未按预期完成安装。以下是相关代码片段:

static final String ACTION_DOWNLOAD_SUBSCRIPTION = "download_subscription";
static final String LPA_DECLARED_PERMISSION = "com.your.company.lpa.permission.BROADCAST";

BroadcastReceiver receiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        if (!action.equals(intent.getAction())) {
            return;
        }
        resultCode = getResultCode();
        detailedCode = intent.getIntExtra(
            EuiccManager.EXTRA_EMBEDDED_SUBSCRIPTION_DETAILED_CODE,
            0 /* defaultValue*/);

        // If the result code is a resolvable error, call startResolutionActivity
        if (resultCode == EuiccManager.EMBEDDED_SUBSCRIPTION_RESULT_RESOLVABLE_ERROR) {
            PendingIntent callbackIntent = PendingIntent.getBroadcast(
                getContext(), 0 /* requestCode */, intent,
                PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE);
            mgr.startResolutionActivity(
                activity,
                0 /* requestCode */,
                intent,
                callbackIntent);
        }

        resultIntent = intent;
    } 
};

context.registerReceiver(receiver,
    new IntentFilter(ACTION_DOWNLOAD_SUBSCRIPTION),
    LPA_DECLARED_PERMISSION /* broadcastPermission*/,
    null /* handler */);

// Download subscription asynchronously.
DownloadableSubscription sub = DownloadableSubscription
.forActivationCode(code /* encodedActivationCode*/);
Intent intent = new Intent(action);
PendingIntent callbackIntent = PendingIntent.getBroadcast(
getContext(), 0 /* requestCode */, intent,
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE);
mgr.downloadSubscription(sub, true /* switchAfterDownload */,
callbackIntent);

排查思路与建议

  • 校验广播Action一致性:代码中onReceive里判断的action变量需与ACTION_DOWNLOAD_SUBSCRIPTION完全一致,否则接收器会直接返回,无法处理下载结果。
  • 完善广播结果处理:在onReceive中添加日志打印resultCode和detailedCode,明确下载请求的状态(成功/失败/其他错误),比如:
    Log.d("eSIMDebug", "Result Code: " + resultCode + ", Detailed Code: " + detailedCode);
    
  • 检查权限配置:
    • 确保Manifest中声明了android.permission.MANAGE_EMBEDDED_SUBSCRIPTIONS权限,且应用已被授予该系统级权限(通常需要系统签名或特殊渠道授权)。
    • 确认LPA_DECLARED_PERMISSION对应的权限在Manifest中正确声明,且系统LPA应用拥有该权限。
  • 验证EuiccManager与设备支持:
    • 确认mgr是通过context.getSystemService(EuiccManager.class)正确获取的,且mgr.isEnabled()返回true(设备支持eSIM)。
  • 检查PendingIntent配置:
    • Android 12+需使用FLAG_MUTABLE,但要确保targetSdkVersion适配;避免重复使用相同requestCode,防止PendingIntent被覆盖。
  • 确认激活码有效性:检查code是否为正确编码的eSIM激活码,包含合法的SM-DP+地址与签名信息。
  • 确认接收器注册时机:确保广播接收器在调用downloadSubscription之前完成注册,避免结果返回时接收器未注册导致事件丢失。

内容的提问来源于stack exchange,提问作者Muhammad Zubair Ashraf

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 02:33:25