Android Esim активация Android ESIM Lui не начинаетAndroid

Форум для тех, кто программирует под Android
Ответить
Anonymous
 Android Esim активация Android ESIM Lui не начинает

Сообщение Anonymous »

Я пытаюсь внедрить приложение Flutter для продажи ESIMS. Airalo предоставляет мне код LPA, который я могу активировать в настройках телефона. Но я хочу дать возможность пользователю запустить активацию ESIM из моего приложения.
Я получил следующий код: < /p>
mainactivity.ktобразной

Код: Выделить всё

package deep.esim.deep_esim_mobile

import io.flutter.embedding.android.FlutterActivity
import io.flutter.plugins.GeneratedPluginRegistrant
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel
import android.os.Bundle

class MainActivity : FlutterActivity() {
private val CHANNEL = "deep.esim.mobile/esim"
private lateinit var esimService: EsimService

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
esimService = EsimService(this)

val flutterEngine = this.getFlutterEngine()
if (flutterEngine != null) {
GeneratedPluginRegistrant.registerWith(flutterEngine)
}
}

override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)

MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler { call, result ->
when (call.method) {
"isEsimAvailable" -> {
try {
val isAvailable = esimService.isEsimAvailable()
result.success(isAvailable)
} catch (e: Exception) {
result.error("ESIM_ERROR", "Failed to check eSIM availability", e.message)
}
}
"startEsimActivation" ->  {
try {
val activationCode = call.argument("activationCode")
if (activationCode != null) {
val success = esimService.startEsimActivation(activationCode)
result.success(success)
} else {
result.error("INVALID_ARGUMENT", "Activation code is required", null)
}
} catch (e: Exception) {
result.error("ESIM_ERROR", "Failed to start eSIM activation", e.message)
}
}
}
}
}
}
< /code>
eSimservice.kt
package deep.esim.deep_esim_mobile

import android.content.Context
import android.telephony.TelephonyManager
import android.telephony.SubscriptionManager
import android.telephony.euicc.EuiccManager
import android.telephony.euicc.DownloadableSubscription
import android.os.Build
import androidx.annotation.RequiresApi

class EsimService(private val context: Context) {

private val telephonyManager: TelephonyManager by lazy {
context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
}

private val subscriptionManager: SubscriptionManager by lazy {
context.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE) as SubscriptionManager
}

private val euiccManager: EuiccManager? by lazy {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
context.getSystemService(Context.EUICC_SERVICE) as EuiccManager
} else {
null
}
}

/**
* Check if eSIM is available on the device
* @return true if eSIM is available, false otherwise
*/
fun isEsimAvailable(): Boolean {
return try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
euiccManager?.isEnabled == true
} else {
telephonyManager.phoneType == TelephonyManager.PHONE_TYPE_GSM ||
telephonyManager.phoneType == TelephonyManager.PHONE_TYPE_CDMA
}
} catch (e: Exception) {
false
}
}

/**
* Start eSIM activation process
* This method triggers the system's LUI (Local User Interface) flow for eSIM activation
*
* @param activationCode The activation code for the eSIM profile
* @return true if activation was started successfully, false otherwise
*/
fun startEsimActivation(activationCode: String): Boolean {
return try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
val manager = euiccManager ?: return false
if (!manager.isEnabled) {
return false
}
val downloadableSubscription = DownloadableSubscription.forActivationCode(activationCode)
val intent = android.content.Intent(context, MainActivity::class.java)
val pendingIntent = android.app.PendingIntent.getActivity(
context,
0,
intent,
android.app.PendingIntent.FLAG_UPDATE_CURRENT or android.app.PendingIntent.FLAG_IMMUTABLE
)
manager.downloadSubscription(
downloadableSubscription,
false,
pendingIntent
)

true
} else {
false
}
} catch (e: Exception) {
false
}
}
}
< /code>
android manifest.kt

















































< /code>
startEsimActivation
возвращает true , но тогда ничего не происходит. Я думаю, что есть проблема с разрешениями моих приложений. Можно ли запустить активацию ESIM без привилегий носителя?


Подробнее здесь: https://stackoverflow.com/questions/797 ... t-starting
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Android»