我试图使用文档eSim中的示例编写在设备上实现https://source.android.com/devices/tech/connect/esim-overview?hl=en的代码测试示例。该设备支持eSim,验证方法mgr.isEnabled()返回true。但是,当我试图调用公共加载方法downloadSubscription时,不会调用onReceive方法。
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*/);
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);
mgr.downloadSubscription(sub, true /* switchAfterDownload */,
callbackIntent);我不太明白到底需要在这里指定什么,"com.your.company.lpa.permission.BROADCAST",我试着把"com.your.company“改为包名,但是它不起作用
发布于 2022-07-25 20:23:52
我正面临着和你一样的问题,真正解决问题的是:
当您创建这样一个新的意图时,将作为参数传递给PendingIntent:
Intent intent = new Intent(action);动作值应该与ACTION_DOWNLOAD_SUBSCRIPTION相同,我在它们上传递了不同的值,您不需要设置LPA_DECLARED_PERMISSION,您可以将null传递给registerBroadcast。
https://stackoverflow.com/questions/67939151
复制相似问题