Я работаю над приложением Flutter, где я пытаюсь загрузить ESIM с кодом LPA. Это в основном приложение оператора, но нет пакета для установки ESIM в Flutter или Pub.DEV. Поэтому мне пришлось использовать нативный код Android с Kotlin, чтобы запустить эту функциональность, я получаю доступ к нему через канал метода в Flutter. Я использую код из Android Docs для имплентрации ESIM, он приводит к действию после нажатия кнопки установки OB, но когда я нажимаю на кнопку в диалоговом окне, он ничего не делает, а диалоговое окно из системы системы. Я нажимаю на да, ничего не происходит. Вот мой код, я использую метод канала для доступа к этому в Flutter. < /P>
class MainActivity: FlutterFragmentActivity() {
private val CHANNEL1 = "com.demo.methodchannel"
private const val DOWNLOAD_ACTION = "download_subscription"
private const val BROADCAST_PERMISSION = "com.your.company.lpa.permission.BROADCAST"
private val TEST_SIM_PROFILE =
"LPA:1\$MTAwMDAwMDAwMzQ2MzM5Y2E2NDgwNQ==$7UMyhYJKZLBfHZt2ve9vQH0oKvE=$"
@RequiresApi(Build.VERSION_CODES.P)
private lateinit var manager: EuiccManager
// Global variable to compare equality missing in android docs
private var resultIntent: Intent? = null
private val ACTION_DOWNLOAD_SUBSCRIPTION = "download_subscription"
private val ACTIVATION_CODE = "LPA:1\$rsp.truphone.com\$JQ-1WDSUO-1IS1KON"
private var mgr: EuiccManager? = null
private val Success = "Success"
@RequiresApi(VERSION_CODES.P)
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL1).setMethodCallHandler {
call, result ->
if (call.method == "messageFunction") {
manager = getSystemService(EUICC_SERVICE) as EuiccManager
//setupEsim()
downloadTestProfile()
} else {
result.notImplemented()
}
}
}
private val eSimBroadcastReceiver = object : BroadcastReceiver() {
@SuppressLint("UnsafeIntentLaunch")
@RequiresApi(Build.VERSION_CODES.P)
override fun onReceive(context: Context, intent: Intent) {
/**
* Check if same action is triggered again after the allow permission dialog.
* if not will throw IntentSender.SendIntentException again fails to be mentioned clearly on android docs
*/
if (resultIntent?.action.equals(intent.action)) {
return
}
val detailedCode =
intent.getIntExtra(EXTRA_EMBEDDED_SUBSCRIPTION_DETAILED_CODE, 0 /* defaultValue*/)
val embeddedOperationCode =
intent.getIntExtra(EXTRA_EMBEDDED_SUBSCRIPTION_OPERATION_CODE, 0 /* defaultValue*/)
/**
* Helps if there is an issue with the e-sim
* Try to print the extras to get all the info like subject or result code.
*/
print("detailedCode: $detailedCode")
print("embeddedOperationCode: $embeddedOperationCode")
when (resultCode) {
EuiccManager.EMBEDDED_SUBSCRIPTION_RESULT_OK -> {
// Success
Toast.makeText(
this@MainActivity,
"Successfully installed eSIM",
Toast.LENGTH_LONG
).show()
}
EuiccManager.EMBEDDED_SUBSCRIPTION_RESULT_RESOLVABLE_ERROR -> {
// Recoverable might be permission issue system will show dialog to allow or deny
val callbackIntent = PendingIntent.getBroadcast(
baseContext,
1 /* requestCode */,
intent,
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE
)
try {
manager?.startResolutionActivity(
this@MainActivity,
0 /* requestCode */,
intent,
callbackIntent
)
} catch (e: IntentSender.SendIntentException) {
print(e)
}
}
else -> Toast.makeText(
this@MainActivity,
"Failed to install eSIM",
Toast.LENGTH_LONG
).show()
}
resultIntent = intent // Assign the intent to the global var for reference
}
}
/**
* Register the broadcast receiver
*/
@SuppressLint("UnspecifiedRegisterReceiverFlag")
override fun onStart() {
super.onStart()
registerReceiver(
eSimBroadcastReceiver,
IntentFilter(DOWNLOAD_ACTION),
BROADCAST_PERMISSION,
null
)
}
/**
* Un-Register the broadcast receiver
*/
override fun onStop() {
super.onStop()
unregisterReceiver(eSimBroadcastReceiver)
}
@RequiresApi(Build.VERSION_CODES.P)
private fun downloadTestProfile() {
manager = getSystemService(EUICC_SERVICE) as EuiccManager
// Check if e-sim is supported by the device note that emulators are not supported.
if (!manager.isEnabled) {
Toast.makeText(this, "eSIM is not supported on this device", Toast.LENGTH_LONG).show()
return
}
val info = manager.euiccInfo
val osVer = info?.osVersion
print("osVer $osVer")
val subscription =
DownloadableSubscription.forActivationCode(PROFILE)
val callbackIntent = PendingIntent.getBroadcast(
baseContext,
0 /* requestCode */,
Intent(DOWNLOAD_ACTION),
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE
)
manager.downloadSubscription(subscription, true, callbackIntent)
}
< /code>
Подробнее здесь: https://stackoverflow.com/questions/776 ... roid-phone
Имея проблемы при попытке установить ESIM напрямую в телефон Android ⇐ Android
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Android — проблема с eUICC при активации eSIM с одним и тем же eSIM на разных устройствах
Anonymous » » в форуме Android - 0 Ответы
- 99 Просмотры
-
Последнее сообщение Anonymous
-