SubscriptionManager.from()已弃用

时间:2018-09-28 11:49:17

标签: android kotlin android-subscriptionmanager

以前,我们曾经使用

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

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

1 个答案:

答案 0 :(得分:1)

我们可以通过以下方式获取SubscriptionManager的实例

Java

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

SubscriptionManager subscriptionManager=getSystemService(SubscriptionManager.class);

对于API> = 23

科特林

val subscriptionManager = getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE) as SubscriptionManager

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

Official Documentation