I am trying to implement eSIM functionality with Flutter as UI and native Java for the EUICC APIs. After debugging it turns out that my code exits right when the new BroadcastReceiver() line executes and skips to the end of the code block and logs ("I am downloading")(No exceptions, No crashes) Last logged value is ("stt3"). Knowing the code works when using a pure native Android project, what could be the issue?
I Have used the same method channel to check for eSIM compatibility and to get the battery level and it works fine
@RequiresApi(api = Build.VERSION_CODES.P)
private void downloadSubscription(){
// Context context = getApplicationContext();
Log.d("init", "ASKJDGAKJHSDHFGKJASF");
EuiccManager mgr = (EuiccManager) context.getSystemService(Context.EUICC_SERVICE);
Log.d("stt2", "ASKJDGAKJHSDHFGKJASF");
// Register receiver.
try {
Log.d("stt3", "stt3");
BroadcastReceiver receiver =
new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Log.d("stt4", "stt4");
if (!ACTION_DOWNLOAD_SUBSCRIPTION.equals(intent.getAction())) {
return;
}
Intent resultIntent = new Intent();
int resultCode = getResultCode();
Log.d("result code", "result code" + resultCode);
int 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(
context , 0 /* requestCode */, intent,
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE);
try {
mgr.startResolutionActivity(
activity,
0 /* requestCode */,
intent,
callbackIntent);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
resultIntent = intent;
Log.d("HALO result code", "result code is " + resultCode);
}
};
context.registerReceiver(receiver,
new IntentFilter(ACTION_DOWNLOAD_SUBSCRIPTION),
LPA_DECLARED_PERMISSION, null /* broadcastPermission*/);
// Download subscription asynchronously.
Log.d("I am downloading ", "I am downloading");
DownloadableSubscription sub = DownloadableSubscription
.forActivationCode("2378462378wjgdjghiw" /* encodedActivationCode*/);
Intent intent = new Intent(ACTION_DOWNLOAD_SUBSCRIPTION).setPackage(context.getPackageName());
PendingIntent callbackIntent = PendingIntent.getBroadcast(
context, 0 /* requestCode */, intent,
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE);
mgr.downloadSubscription(sub, true /* switchAfterDownload */,
callbackIntent);
} catch (Exception e){
Log.d("lblblblblb", "lblblblblb I AM EXCEPTION " + e);
throw new RuntimeException(e);
}
}