SubscriptionManager.from() 已弃用

SubscriptionManager.from() Deprecated

以前我们使用

获取SubscriptionManager的实例
SubscriptionManager subscriptionManager=SubscriptionManager.from(this);

但是 SubscriptionManager.from(context) 在 API 28 中被弃用,获取 SubscriptionManager 实例的新方法是什么?

我们可以使用以下方式获取 SubscriptionManager 的实例

Java

 SubscriptionManager subscriptionManager= (SubscriptionManager) getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);

SubscriptionManager subscriptionManager=getSystemService(SubscriptionManager.class);

对于API>=23

Kotlin

val subscriptionManager = getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE) as SubscriptionManager

var subscriptionManager = getSystemService(SubscriptionManager::class.java)

Official Documentation